param.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <cl-crud @load="onLoad">
  3. <template #slot-content="{ scope }">
  4. <div class="editor" v-for="(item, index) in tab.list" :key="index">
  5. <template v-if="tab.index === index">
  6. <el-button class="change-btn" size="mini" @click="changeTab(item.to)">{{
  7. item.label
  8. }}</el-button>
  9. <component :is="item.component" height="300px" v-model="scope.data"></component>
  10. </template>
  11. </div>
  12. </template>
  13. <el-row type="flex">
  14. <cl-refresh-btn></cl-refresh-btn>
  15. <cl-add-btn></cl-add-btn>
  16. <cl-multi-delete-btn></cl-multi-delete-btn>
  17. <cl-flex1></cl-flex1>
  18. <cl-search-key></cl-search-key>
  19. </el-row>
  20. <el-row>
  21. <cl-table v-bind="table"></cl-table>
  22. </el-row>
  23. <el-row type="flex">
  24. <cl-flex1></cl-flex1>
  25. <cl-pagination></cl-pagination>
  26. </el-row>
  27. <cl-upsert ref="upsert" v-bind="upsert" @open="onUpsertOpen">
  28. <template #slot-content="{ scope }">
  29. <div class="editor" v-for="(item, index) in tab.list" :key="index">
  30. <template v-if="tab.index === index">
  31. <el-button class="change-btn" size="mini" @click="changeTab(item.to)">{{
  32. item.label
  33. }}</el-button>
  34. <component
  35. :is="item.component"
  36. height="300px"
  37. v-model="scope.data"
  38. ></component>
  39. </template>
  40. </div>
  41. </template>
  42. </cl-upsert>
  43. </cl-crud>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. tab: {
  50. index: null,
  51. list: [
  52. {
  53. label: "切换富文本编辑器",
  54. to: 1,
  55. component: "cl-codemirror"
  56. },
  57. {
  58. label: "切换代码编辑器",
  59. to: 0,
  60. component: "cl-editor-quill"
  61. }
  62. ]
  63. },
  64. table: {
  65. columns: [
  66. {
  67. type: "selection",
  68. align: "center",
  69. width: 60
  70. },
  71. {
  72. label: "名称",
  73. prop: "name",
  74. align: "center",
  75. "min-width": 150
  76. },
  77. {
  78. label: "keyName",
  79. prop: "keyName",
  80. align: "center",
  81. "min-width": 150
  82. },
  83. {
  84. label: "数据",
  85. prop: "data",
  86. align: "center",
  87. "min-width": 150,
  88. "show-overflow-tooltip": true
  89. },
  90. {
  91. label: "备注",
  92. prop: "remark",
  93. align: "center",
  94. "min-width": 200,
  95. "show-overflow-tooltip": true
  96. },
  97. {
  98. label: "操作",
  99. align: "center",
  100. type: "op"
  101. }
  102. ]
  103. },
  104. upsert: {
  105. props: {
  106. width: "1000px"
  107. },
  108. items: [
  109. {
  110. prop: "name",
  111. label: "名称",
  112. span: 12,
  113. component: {
  114. name: "el-input",
  115. attrs: {
  116. placeholder: "请输入名称"
  117. }
  118. },
  119. rules: {
  120. required: true,
  121. message: "名称不能为空"
  122. }
  123. },
  124. {
  125. prop: "keyName",
  126. label: "keyName",
  127. span: 12,
  128. component: {
  129. name: "el-input",
  130. attrs: {
  131. placeholder: "请输入Key"
  132. }
  133. },
  134. rules: {
  135. required: true,
  136. message: "Key不能为空"
  137. }
  138. },
  139. {
  140. prop: "data",
  141. label: "数据",
  142. component: {
  143. name: "slot-content"
  144. }
  145. },
  146. {
  147. prop: "remark",
  148. label: "备注",
  149. component: {
  150. name: "el-input",
  151. props: {
  152. type: "textarea"
  153. },
  154. attrs: {
  155. placeholder: "请输入备注",
  156. rows: 3
  157. }
  158. }
  159. }
  160. ]
  161. }
  162. };
  163. },
  164. methods: {
  165. onLoad({ ctx, app }) {
  166. ctx.service(this.$service.system.param).done();
  167. app.refresh();
  168. },
  169. changeTab(i) {
  170. this.$confirm("切换编辑器会清空输入内容,是否继续?", "提示", {
  171. type: "warning"
  172. })
  173. .then(() => {
  174. this.tab.index = i;
  175. this.$refs["upsert"].setForm("data", "");
  176. })
  177. .catch(() => {});
  178. },
  179. onUpsertOpen(isEdit, data) {
  180. this.tab.index = null;
  181. this.$nextTick(() => {
  182. if (isEdit) {
  183. this.tab.index = /<*>/g.test(data.data) ? 1 : 0;
  184. } else {
  185. this.tab.index = 1;
  186. }
  187. });
  188. }
  189. }
  190. };
  191. </script>
  192. <style lang="scss" scoped>
  193. .change-btn {
  194. display: flex;
  195. position: absolute;
  196. right: 10px;
  197. bottom: 10px;
  198. z-index: 9;
  199. }
  200. .editor {
  201. transition: all 0.3s;
  202. }
  203. </style>