queryModal.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. <a-row :gutter="24">
  14. <a-col :md="4" :sm="24">
  15. <!-- <div class="copy-btn-box-9136076486841527"> -->
  16. 数据库表名:
  17. <!-- <a-input placeholder="请输入表名" style="width:20%;" v-model="businessTable" />&nbsp; -->
  18. <!-- </div> -->
  19. </a-col>
  20. <a-col :md="18" :sm="24">
  21. <a-select v-model="businessTable" style="width: 30%" placeholder="请选择数据库表名" allowClear show-search >
  22. <a-select-option v-for="(item) in tableList" :key="item.tableName" :value="item.tableName">{{item.tableName}}{{item.tableComment}}</a-select-option>
  23. </a-select>
  24. </a-col>
  25. </a-row>
  26. <a-row :gutter="24" v-if="dataSource.length>0">
  27. <a-col :md="24" :sm="24">
  28. <a-alert message="目前该数据库表关联的表单存在多个,请选择其中一个!" type="info" banner/><br>
  29. <a-table
  30. bordered
  31. :data-source="dataSource"
  32. :columns="columns"
  33. :rowKey="record=>record.id"
  34. :pagination="false"
  35. style="margin-top:5px"
  36. >
  37. <template slot="operation" slot-scope="text, record">
  38. <a href="javascript:;" @click="textClick(record)">确定</a>
  39. </template>
  40. </a-table>
  41. </a-col>
  42. </a-row>
  43. </a-modal>
  44. </template>
  45. <script>
  46. import { getFormByBusinessTable,getTableList } from "../../api/api";
  47. /*
  48. * author kcz
  49. * date 2019-11-20
  50. * description 导入json Modal
  51. */
  52. export default {
  53. name: "queryModal",
  54. data() {
  55. return {
  56. tableList:[],
  57. dataSource:[],
  58. columns:[
  59. {
  60. title: '表单名称',
  61. dataIndex: 'text',
  62. scopedSlots: { customRender: 'text' },
  63. },
  64. {
  65. title: '数据库表名',
  66. dataIndex: 'businessTable',
  67. },
  68. {
  69. title: '表单描述',
  70. dataIndex: 'stepMemo',
  71. },
  72. {
  73. title: '操作',
  74. dataIndex: 'operation',
  75. scopedSlots: { customRender: 'operation' },
  76. }
  77. ],
  78. visible: false,
  79. jsonData: {},
  80. handleSetSelectItem: null,
  81. text: "", //表单标题
  82. businessTable: "", //数据库表名称
  83. formData: {}
  84. };
  85. },
  86. created(){
  87. //获取数据库表名下拉数据
  88. getTableList().then(res=>{
  89. if(res.data.success){
  90. this.tableList=res.data.result;
  91. }
  92. });
  93. },
  94. methods: {
  95. handleCancel() {
  96. this.visible = false;
  97. },
  98. beforeUpload(e) {
  99. // 通过json文件导入
  100. const _this = this;
  101. const reader = new FileReader();
  102. reader.readAsText(e);
  103. reader.onload = function() {
  104. _this.jsonFormat = this.result;
  105. _this.handleImportJson();
  106. };
  107. return false;
  108. },
  109. textClick(data){
  110. console.log(data)
  111. //获取json展示的数据
  112. this.jsonData.list = data.jsonContent.list;
  113. this.jsonData.config = data.jsonContent.config;
  114. this.jsonData.config.layout = data.jsonContent.config.layout;
  115. //当前填写数据存储,用于其他页面获取
  116. this.formData.businessTable=data.businessTable;//数据库表明
  117. this.formData.text=data.text;//表单标题
  118. this.formData.stepMemo=data.stepMemo;//表单标题
  119. this.handleCancel();
  120. },
  121. handleImportJson() {
  122. // 查询JSON
  123. try {
  124. //判断是否填写数据库表明
  125. if (!this.businessTable) {
  126. this.$message.error("请输入数据库表明");
  127. return;
  128. }
  129. //调用查询接口
  130. getFormByBusinessTable(this.businessTable).then(res => {
  131. if (res.data.success) {
  132. if(res.data.result.tbTableInfoList!=null&&res.data.result.tbTableInfoList.length>1){
  133. this.dataSource=res.data.result.tbTableInfoList;
  134. }else{
  135. //获取Json字符串装json格式
  136. const editorJsonData = res.data.result.jsonContent;
  137. //获取json展示的数据
  138. this.jsonData.list = editorJsonData.list;
  139. this.jsonData.config = editorJsonData.config;
  140. this.jsonData.config.layout = editorJsonData.config.layout;
  141. //当前填写数据存储,用于其他页面获取
  142. this.formData.businessTable = this.businessTable; //数据库表明
  143. this.formData.text = res.data.result.text; //表单标题
  144. this.formData.stepMemo=res.data.result.stepMemo;//表单备注
  145. this.businessTable = ""; //清空
  146. this.dataSource=[];
  147. this.handleCancel();
  148. }
  149. this.$message.success("查询成功");
  150. } else {
  151. this.$message.error(res.data.message);
  152. }
  153. });
  154. // const editorJsonData = JSON.parse(this.jsonFormat);
  155. // this.jsonData.list = editorJsonData.list;
  156. // this.jsonData.config = editorJsonData.config;
  157. // this.jsonData.config.layout = editorJsonData.config.layout;
  158. // this.handleCancel();
  159. // // 导入之后,需要清除已选择key
  160. // this.handleSetSelectItem({ key: "" });
  161. // this.$message.success("导入成功");
  162. } catch (error) {
  163. console.error(error);
  164. this.$message.error("导入失败,数据格式不对");
  165. }
  166. }
  167. }
  168. };
  169. </script>
  170. <style lang="less" scoped>
  171. .hint-box {
  172. background: #e9e9e9;
  173. margin: 0;
  174. border-bottom: 2px solid #fff;
  175. }
  176. </style>