param.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <cl-crud ref="Crud">
  3. <cl-row>
  4. <cl-refresh-btn />
  5. <cl-add-btn />
  6. <cl-multi-delete-btn />
  7. <cl-filter label="数据类型">
  8. <cl-select :options="options.dataType" prop="dataType" :width="120"></cl-select>
  9. </cl-filter>
  10. <cl-flex1 />
  11. <cl-search-key placeholder="搜索名称、keyName" />
  12. </cl-row>
  13. <cl-row>
  14. <cl-table ref="Table" />
  15. </cl-row>
  16. <cl-row>
  17. <cl-flex1 />
  18. <cl-pagination />
  19. </cl-row>
  20. <cl-upsert ref="Upsert" />
  21. </cl-crud>
  22. </template>
  23. <script lang="ts" name="sys-param" setup>
  24. import { setFocus, useCrud, useTable, useUpsert } from "@cool-vue/crud";
  25. import { Document } from "@element-plus/icons-vue";
  26. import { reactive } from "vue";
  27. import { useCool } from "/@/cool";
  28. const { service } = useCool();
  29. // 选项
  30. const options = reactive({
  31. dataType: [
  32. {
  33. label: "字符串",
  34. value: 0,
  35. type: "info"
  36. },
  37. {
  38. label: "富文本",
  39. value: 1,
  40. type: "success"
  41. },
  42. {
  43. label: "文件",
  44. value: 2
  45. }
  46. ]
  47. });
  48. // cl-crud
  49. const Crud = useCrud({ service: service.base.sys.param }, (app) => {
  50. app.refresh();
  51. });
  52. // cl-table
  53. const Table = useTable({
  54. columns: [
  55. {
  56. type: "selection",
  57. width: 60
  58. },
  59. {
  60. label: "名称",
  61. prop: "name",
  62. minWidth: 150
  63. },
  64. {
  65. label: "keyName",
  66. prop: "keyName",
  67. minWidth: 150
  68. },
  69. {
  70. label: "数据类型",
  71. prop: "dataType",
  72. minWidth: 150,
  73. dict: options.dataType
  74. },
  75. {
  76. label: "备注",
  77. prop: "remark",
  78. minWidth: 200,
  79. showOverflowTooltip: true
  80. },
  81. {
  82. label: "操作",
  83. type: "op"
  84. }
  85. ]
  86. });
  87. // cl-upsert
  88. const Upsert = useUpsert({
  89. dialog: {
  90. width: "1000px"
  91. },
  92. items: [
  93. {
  94. prop: "name",
  95. label: "名称",
  96. span: 12,
  97. required: true,
  98. component: {
  99. name: "el-input"
  100. }
  101. },
  102. {
  103. prop: "keyName",
  104. label: "keyName",
  105. span: 12,
  106. required: true,
  107. component: {
  108. name: "el-input",
  109. props: {
  110. placeholder: "请输入Key"
  111. }
  112. }
  113. },
  114. {
  115. prop: "dataType",
  116. label: "类型",
  117. value: 0,
  118. required: true,
  119. component: {
  120. name: "el-radio-group",
  121. options: options.dataType
  122. }
  123. },
  124. {
  125. prop: "data_0",
  126. label: "数据",
  127. hidden({ scope }) {
  128. return scope.dataType != 0;
  129. },
  130. required: true,
  131. component: {
  132. name: "el-input",
  133. props: {
  134. rows: 12,
  135. type: "textarea"
  136. }
  137. }
  138. },
  139. {
  140. prop: "data_1",
  141. label: "数据",
  142. hidden({ scope }) {
  143. return scope.dataType != 1;
  144. },
  145. required: true,
  146. component: {
  147. name: "cl-editor",
  148. props: {
  149. name: "cl-editor-wang"
  150. }
  151. }
  152. },
  153. {
  154. prop: "data_2",
  155. label: "数据",
  156. required: true,
  157. hidden({ scope }) {
  158. return scope.dataType != 2;
  159. },
  160. component: {
  161. name: "cl-upload",
  162. props: {
  163. icon: Document,
  164. multiple: true,
  165. type: "file"
  166. }
  167. }
  168. },
  169. {
  170. prop: "remark",
  171. label: "备注",
  172. component: {
  173. name: "el-input",
  174. props: {
  175. placeholder: "请输入备注",
  176. rows: 3,
  177. type: "textarea"
  178. }
  179. }
  180. }
  181. ],
  182. onOpened(data) {
  183. data[`data_${data.dataType}`] = data.data;
  184. },
  185. onSubmit(data, { next }) {
  186. next({
  187. ...data,
  188. data: data[`data_${data.dataType}`],
  189. data_0: undefined,
  190. data_1: undefined,
  191. data_2: undefined
  192. });
  193. },
  194. plugins: [setFocus()]
  195. });
  196. </script>