index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <div>
  3. <div class="json-box-9136076486841527">
  4. <codemirror style="height:100%;" ref="myEditor" :value="editorJson"></codemirror>
  5. </div>
  6. <div></div>
  7. <a-form-model :model="formData" :label-col="labelCol" :wrapper-col="wrapperCol">
  8. <a-row :gutter="24">
  9. <a-col :span="8">
  10. <a-form-model-item label="表单名">
  11. <a-input v-model="formData.text" placeholder="请输入表名" />
  12. </a-form-model-item>
  13. </a-col>
  14. <a-col :span="8">
  15. <a-form-model-item label="数据库表名">
  16. <a-select
  17. v-model="formData.businessTable"
  18. style="width: 100%"
  19. placeholder="请选择数据库表名"
  20. allowClear
  21. show-search
  22. >
  23. <a-select-option
  24. v-for="(item) in tableList"
  25. :key="item.tableName"
  26. :value="item.tableName"
  27. >{{item.tableName}}{{item.tableComment}}</a-select-option>
  28. </a-select>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :span="8">
  32. <a-form-model-item>
  33. <span slot="label">
  34. 表单描述&nbsp;
  35. <a-tooltip>
  36. <template slot="title">用来明确表单的使用含义</template>
  37. <a-icon type="question-circle-o" />
  38. </a-tooltip>
  39. </span>
  40. <a-input placeholder="请输入表单描述" v-model="formData.stepMemo" />
  41. </a-form-model-item>
  42. </a-col>
  43. </a-row>
  44. <a-row :gutter="24">
  45. <a-col :span="8">
  46. <a-form-model-item label="表单类型">
  47. <a-radio-group v-model="formData.type" :disabled="disabled">
  48. <a-radio value="1">PC端</a-radio>
  49. <a-radio value="2">钉钉端</a-radio>
  50. </a-radio-group>
  51. </a-form-model-item>
  52. </a-col>
  53. </a-row>
  54. </a-form-model>
  55. <!-- <div style="padding-top: 8px">
  56. 表单名:
  57. <a-input placeholder="请输入表名" style="width:20%;" v-model="formData.text" />&nbsp;
  58. 数据库表名:
  59. <a-select
  60. v-model="formData.businessTable"
  61. style="width: 20%"
  62. placeholder="请选择数据库表名"
  63. allowClear
  64. show-search
  65. >
  66. <a-select-option
  67. v-for="(item) in tableList"
  68. :key="item.tableName"
  69. :value="item.tableName"
  70. >{{item.tableName}}{{item.tableComment}}</a-select-option>
  71. </a-select>表单描述
  72. <a-tooltip>
  73. <template slot="title">用来明确表单的使用含义</template>
  74. <a-icon type="question-circle-o" />
  75. </a-tooltip>:
  76. <a-input placeholder="请输入表单描述" style="width:20%;" v-model="formData.stepMemo" />&nbsp;
  77. </div> -->
  78. <div class="copy-btn-box-9136076486841527" style="text-align:right">
  79. <a-divider style="margin: 5px 0;" />
  80. <a-button
  81. @click="handleCopyJson"
  82. type="primary"
  83. class="copy-btn"
  84. data-clipboard-action="copy"
  85. :data-clipboard-text="editorJson"
  86. >复制数据</a-button>
  87. <a-button @click="handleExportJson" type="primary">导出代码</a-button>&nbsp;
  88. <a-button @click="save" type="primary">保存</a-button>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. // 剪切板组件
  94. import Clipboard from "clipboard";
  95. import { codemirror } from "vue-codemirror-lite";
  96. import { getIdcsList, formAdd, getTableList } from "../api/api";
  97. export default {
  98. name: "PreviewCode",
  99. props: {
  100. fileFormat: {
  101. type: String,
  102. default: "json"
  103. },
  104. editorJson: {
  105. type: String,
  106. default: ""
  107. },
  108. formData: {
  109. default: function() {
  110. return {};
  111. }
  112. }
  113. },
  114. data() {
  115. return {
  116. visible: false,
  117. businessTable: "",
  118. text: "",
  119. tableList: [], //数据库下拉列表数据
  120. labelCol: { span: 8 },
  121. wrapperCol: { span: 16 },
  122. disabled:false
  123. };
  124. },
  125. created() {
  126. this.initial();
  127. //获取数据库表名下拉数据
  128. getTableList().then(res => {
  129. if (res.data.success) {
  130. this.tableList = res.data.result;
  131. }
  132. });
  133. },
  134. components: {
  135. codemirror
  136. },
  137. methods: {
  138. initial(){
  139. //判断是否修改进入,修改进入则禁用修改表单类型
  140. if(this.formData.text){
  141. this.disabled=true;
  142. }else{
  143. this.formData.type='1'//默认表单类型为PC端
  144. }
  145. }
  146. ,
  147. exportData(data, fileName = `demo.${this.fileFormat}`) {
  148. let content = "data:text/csv;charset=utf-8,";
  149. content += data;
  150. var encodedUri = encodeURI(content);
  151. var actions = document.createElement("a");
  152. actions.setAttribute("href", encodedUri);
  153. actions.setAttribute("download", fileName);
  154. actions.click();
  155. },
  156. handleExportJson() {
  157. // 导出JSON
  158. getIdcsList();
  159. console.log(this.editorJson);
  160. this.exportData(this.editorJson);
  161. },
  162. save() {
  163. const json = JSON.stringify(this.editorJson).toString();
  164. if (json.indexOf("<div>") != -1) {
  165. this.$message.error("保存数据不是json格式");
  166. return;
  167. }
  168. if (!this.formData.businessTable) {
  169. this.$message.error("请输入数据库表名");
  170. return;
  171. }
  172. if (!this.formData.text) {
  173. this.$message.error("请输入表单名");
  174. return;
  175. }
  176. if (!this.formData.stepMemo) {
  177. this.$message.error("请输入表单描述");
  178. return;
  179. }
  180. if(!this.formData.type){
  181. this.$message.error("请选择表单类型");
  182. return;
  183. }
  184. console.log(this.editorJson);
  185. //定义保存数据格式
  186. const formData = {
  187. text: this.formData.text,
  188. routeName: "自定义$" + this.formData.businessTable,
  189. businessTable: this.formData.businessTable,
  190. jsonContent: JSON.parse(this.editorJson),
  191. stepMemo: this.formData.stepMemo,
  192. type: this.formData.type
  193. };
  194. console.log(formData);
  195. //保存接口
  196. formAdd(formData).then(res => {
  197. if (res.data.success) {
  198. this.$message.config({top: '600px'})
  199. this.$message.success("保存成功");
  200. } else {
  201. this.$message.error("保存失败");
  202. }
  203. });
  204. },
  205. handleCopyJson() {
  206. // 复制数据
  207. const clipboard = new Clipboard(".copy-btn");
  208. clipboard.on("success", () => {
  209. this.$message.success("复制成功");
  210. });
  211. clipboard.on("error", () => {
  212. this.$message.error("复制失败");
  213. });
  214. setTimeout(() => {
  215. // 销毁实例
  216. clipboard.destroy();
  217. }, 122);
  218. }
  219. }
  220. };
  221. </script>