selectModal.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <a-modal
  3. title="请选择表单关联的数据表"
  4. :visible="visible"
  5. @ok="handleImportJson"
  6. @cancel="handleCancel"
  7. cancelText="关闭"
  8. :destroyOnClose="true"
  9. wrapClassName="code-modal-9136076486841527"
  10. style="top:20px;"
  11. width="850px"
  12. >
  13. <div class="copy-btn-box-9136076486841527">
  14. 数据库表名:
  15. <a-input placeholder="请输入表名" style="width:20%;" v-model="businessTable" />&nbsp;
  16. </div>
  17. </a-modal>
  18. </template>
  19. <script>
  20. import { getFormByBusinessTable } from '../../api/api';
  21. /*
  22. * author kcz
  23. * date 2019-11-20
  24. * description 导入json Modal
  25. */
  26. export default {
  27. name: "selectModal",
  28. data() {
  29. return {
  30. visible: false,
  31. jsonData: {},
  32. handleSetSelectItem: null,
  33. text:"",//表单标题
  34. businessTable:""//数据库表名称
  35. ,formData:{}
  36. };
  37. },
  38. methods: {
  39. handleCancel() {
  40. this.visible = false;
  41. },
  42. beforeUpload(e) {
  43. // 通过json文件导入
  44. const _this = this;
  45. const reader = new FileReader();
  46. reader.readAsText(e);
  47. reader.onload = function() {
  48. _this.jsonFormat = this.result;
  49. _this.handleImportJson();
  50. };
  51. return false;
  52. },
  53. handleImportJson() {
  54. // 查询JSON
  55. try {
  56. //判断是否填写数据库表明
  57. if(!this.businessTable){
  58. this.$message.error("请输入数据库表明");
  59. return;
  60. }
  61. //调用查询接口
  62. getFormByBusinessTable(this.businessTable).then(res=>{
  63. if(res.data.success){
  64. //获取Json字符串装json格式
  65. const editorJsonData = res.data.result.jsonContent;
  66. //获取json展示的数据
  67. this.jsonData.list = editorJsonData.list;
  68. this.jsonData.config = editorJsonData.config;
  69. this.jsonData.config.layout = editorJsonData.config.layout;
  70. //当前填写数据存储,用于其他页面获取
  71. this.formData.businessTable=this.businessTable;//数据库表明
  72. this.formData.text=res.data.result.text;//表单标题
  73. this.businessTable="";//清空
  74. this.handleCancel();
  75. this.$message.success("查询成功");
  76. }else{
  77. this.$message.error(res.data.message);
  78. }
  79. })
  80. // const editorJsonData = JSON.parse(this.jsonFormat);
  81. // this.jsonData.list = editorJsonData.list;
  82. // this.jsonData.config = editorJsonData.config;
  83. // this.jsonData.config.layout = editorJsonData.config.layout;
  84. // this.handleCancel();
  85. // // 导入之后,需要清除已选择key
  86. // this.handleSetSelectItem({ key: "" });
  87. // this.$message.success("导入成功");
  88. } catch (error) {
  89. console.error(error);
  90. this.$message.error("导入失败,数据格式不对");
  91. }
  92. }
  93. }
  94. };
  95. </script>
  96. <style lang="less" scoped>
  97. .hint-box {
  98. background: #e9e9e9;
  99. margin: 0;
  100. border-bottom: 2px solid #fff;
  101. }
  102. </style>