queryModal.vue 6.3 KB

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