commonCrud.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import {dict} from "@fast-crud/fast-crud";
  2. import {shallowRef} from 'vue'
  3. import deptFormat from "/@/components/dept-format/index.vue";
  4. export const commonCrudConfig = (options = {
  5. create_datetime: {
  6. form: false,
  7. table: false,
  8. search: false
  9. },
  10. update_datetime: {
  11. form: false,
  12. table: false,
  13. search: false
  14. },
  15. creator_name: {
  16. form: false,
  17. table: false,
  18. search: false
  19. },
  20. modifier_name: {
  21. form: false,
  22. table: false,
  23. search: false
  24. },
  25. dept_belong_id: {
  26. form: false,
  27. table: false,
  28. search: false
  29. },
  30. description: {
  31. form: false,
  32. table: false,
  33. search: false
  34. },
  35. }) => {
  36. return {
  37. dept_belong_id: {
  38. title: '所属部门',
  39. type: 'dict-tree',
  40. search: {
  41. show: options.dept_belong_id?.search || false
  42. },
  43. dict: dict({
  44. url: '/api/system/dept/all_dept/',
  45. isTree: true,
  46. value: 'id',
  47. label: 'name',
  48. children: 'children',
  49. }),
  50. column: {
  51. align: 'center',
  52. width: 300,
  53. show: options.dept_belong_id?.table || false,
  54. component: {
  55. name: shallowRef(deptFormat),
  56. vModel: "modelValue",
  57. }
  58. },
  59. form: {
  60. show: options.dept_belong_id?.form || false,
  61. component: {
  62. multiple: false,
  63. clearable: true,
  64. props: {
  65. checkStrictly: true,
  66. props: {
  67. // 为什么这里要写两层props
  68. // 因为props属性名与fs的动态渲染的props命名冲突,所以要多写一层
  69. label: "name",
  70. value: "id",
  71. }
  72. }
  73. },
  74. helper: "默认不填则为当前创建用户的部门ID"
  75. }
  76. },
  77. description: {
  78. title: '备注',
  79. search: {
  80. show: options.description?.search || false
  81. },
  82. type: 'textarea',
  83. column: {
  84. width: 100,
  85. show: options.description?.table || false,
  86. },
  87. form: {
  88. show: options.description?.form || false,
  89. component: {
  90. placeholder: '请输入内容',
  91. showWordLimit: true,
  92. maxlength: '200',
  93. }
  94. },
  95. viewForm: {
  96. show: true
  97. }
  98. },
  99. modifier_name: {
  100. title: '修改人',
  101. search: {
  102. show: options.modifier_name?.search || false
  103. },
  104. column: {
  105. width: 100,
  106. show: options.modifier_name?.table || false,
  107. },
  108. form: {
  109. show: false,
  110. },
  111. viewForm: {
  112. show: true
  113. }
  114. },
  115. creator_name: {
  116. title: '创建人',
  117. search: {
  118. show: options.creator_name?.search || false
  119. },
  120. column: {
  121. width: 100,
  122. show: options.creator_name?.table || false,
  123. },
  124. form: {
  125. show: false,
  126. },
  127. viewForm: {
  128. show: true
  129. }
  130. },
  131. update_datetime: {
  132. title: '更新时间',
  133. type: 'datetime',
  134. search: {
  135. show: options.update_datetime?.search || false,
  136. col: {span: 8},
  137. component: {
  138. type: 'datetimerange',
  139. props: {
  140. 'start-placeholder': '开始时间',
  141. 'end-placeholder': '结束时间',
  142. 'value-format': 'YYYY-MM-DD HH:mm:ss',
  143. 'picker-options': {
  144. shortcuts: [{
  145. text: '最近一周',
  146. onClick(picker) {
  147. const end = new Date();
  148. const start = new Date();
  149. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  150. picker.$emit('pick', [start, end]);
  151. }
  152. }, {
  153. text: '最近一个月',
  154. onClick(picker) {
  155. const end = new Date();
  156. const start = new Date();
  157. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  158. picker.$emit('pick', [start, end]);
  159. }
  160. }, {
  161. text: '最近三个月',
  162. onClick(picker) {
  163. const end = new Date();
  164. const start = new Date();
  165. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  166. picker.$emit('pick', [start, end]);
  167. }
  168. }]
  169. }
  170. }
  171. },
  172. valueResolve(context: any) {
  173. const {key, value} = context
  174. //value解析,就是把组件的值转化为后台所需要的值
  175. //在form表单点击保存按钮后,提交到后台之前执行转化
  176. if (value) {
  177. context.form.update_datetime_after = value[0]
  178. context.form.update_datetime_before = value[1]
  179. }
  180. // ↑↑↑↑↑ 注意这里是form,不是row
  181. }
  182. },
  183. column: {
  184. width: 160,
  185. show: options.update_datetime?.table || false,
  186. },
  187. form: {
  188. show: false,
  189. },
  190. viewForm: {
  191. show: true
  192. }
  193. },
  194. create_datetime: {
  195. title: '创建时间',
  196. type: 'datetime',
  197. search: {
  198. show: options.create_datetime?.search || false,
  199. col: {span: 8},
  200. component: {
  201. type: 'datetimerange',
  202. props: {
  203. 'start-placeholder': '开始时间',
  204. 'end-placeholder': '结束时间',
  205. 'value-format': 'YYYY-MM-DD HH:mm:ss',
  206. 'picker-options': {
  207. shortcuts: [{
  208. text: '最近一周',
  209. onClick(picker) {
  210. const end = new Date();
  211. const start = new Date();
  212. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  213. picker.$emit('pick', [start, end]);
  214. }
  215. }, {
  216. text: '最近一个月',
  217. onClick(picker) {
  218. const end = new Date();
  219. const start = new Date();
  220. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  221. picker.$emit('pick', [start, end]);
  222. }
  223. }, {
  224. text: '最近三个月',
  225. onClick(picker) {
  226. const end = new Date();
  227. const start = new Date();
  228. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  229. picker.$emit('pick', [start, end]);
  230. }
  231. }]
  232. }
  233. }
  234. },
  235. valueResolve(context: any) {
  236. const {key, value} = context
  237. //value解析,就是把组件的值转化为后台所需要的值
  238. //在form表单点击保存按钮后,提交到后台之前执行转化
  239. if (value) {
  240. context.form.create_datetime_after = value[0]
  241. context.form.create_datetime_before = value[1]
  242. }
  243. // ↑↑↑↑↑ 注意这里是form,不是row
  244. }
  245. },
  246. column: {
  247. width: 160,
  248. show: options.create_datetime?.table || false,
  249. },
  250. form: {
  251. show: false
  252. },
  253. viewForm: {
  254. show: true
  255. }
  256. }
  257. }
  258. }