crud.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import * as api from './api';
  2. import { dict, UserPageQuery, AddReq, DelReq, EditReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
  3. import { inject, nextTick, ref } from 'vue';
  4. import { successMessage } from '/@/utils/message';
  5. import { BaseColumn } from '/@/views/adManage/utils/commonTabColumn.js';
  6. export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  7. const pageRequest = async (query: UserPageQuery) => {
  8. return await api.GetList(query);
  9. };
  10. const editRequest = async ({ form, row }: EditReq) => {
  11. form.id = row.id;
  12. return await api.UpdateObj(form);
  13. };
  14. const delRequest = async ({ row }: DelReq) => {
  15. return await api.DelObj(row.id);
  16. };
  17. const addRequest = async ({ form }: AddReq) => {
  18. return await api.AddObj(form);
  19. };
  20. //权限判定
  21. const hasPermissions = inject('$hasPermissions');
  22. return {
  23. crudOptions: {
  24. table: {
  25. height: 800,
  26. },
  27. container: {
  28. fixedHeight: false
  29. },
  30. request: {
  31. pageRequest,
  32. addRequest,
  33. editRequest,
  34. delRequest,
  35. },
  36. rowHandle: {
  37. fixed: 'right',
  38. width: 80,
  39. buttons: {
  40. view: {
  41. show: false,
  42. },
  43. edit: {
  44. iconRight: 'Edit',
  45. type: 'text',
  46. text: null
  47. // show: hasPermissions('dictionary:Update'),
  48. },
  49. remove: {
  50. iconRight: 'Delete',
  51. type: 'text',
  52. text: null
  53. // show: hasPermissions('dictionary:Delete'),
  54. },
  55. // custom: {
  56. // text: '字典配置',
  57. // type: 'text',
  58. // // show: hasPermissions('dictionary:Update'),
  59. // tooltip: {
  60. // placement: 'top',
  61. // content: '字典配置',
  62. // },
  63. // //@ts-ignore
  64. // click: (ctx: any) => {
  65. // const { row } = ctx;
  66. // context!.subDictRef.value.drawer = true;
  67. // nextTick(() => {
  68. // context!.subDictRef.value.setSearchFormData({ form: { parent: row.id } });
  69. // context!.subDictRef.value.doRefresh();
  70. // });
  71. // },
  72. // },
  73. },
  74. },
  75. columns: {
  76. // _index: {
  77. // title: '序号',
  78. // form: { show: false },
  79. // column: {
  80. // //type: 'index',
  81. // align: 'center',
  82. // width: '70px',
  83. // columnSetDisabled: true, //禁止在列设置中选择
  84. // formatter: (context) => {
  85. // //计算序号,你可以自定义计算规则,此处为翻页累加
  86. // let index = context.index ?? 1;
  87. // let pagination = crudExpose!.crudBinding.value.pagination;
  88. // // @ts-ignore
  89. // return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1;
  90. // },
  91. // },
  92. // },
  93. name: {
  94. title: '广告组合',
  95. column: {
  96. width: '150px'
  97. },
  98. search: {
  99. show: true,
  100. component: {
  101. props: {
  102. clearable: true
  103. }
  104. }
  105. },
  106. form: {
  107. rules: [{required: true, message:'必填项'}]
  108. }
  109. },
  110. state: {
  111. title: '状态',
  112. type: 'dict-select',
  113. dict: dict({
  114. data:[
  115. {value:'enabled', label:'投放中'},
  116. {value:'disable', label:'禁用'},
  117. ]
  118. }),
  119. form: {
  120. show: false
  121. }
  122. },
  123. budget_policy: {
  124. title: '预算类型',
  125. type: 'dict-select',
  126. dict: dict({
  127. data: [
  128. { value: '', label: '无预算上限' },
  129. { value: 'dateRange', label: '日期范围' },
  130. { value: 'monthlyRecurring', label: '按月' },
  131. ]
  132. }),
  133. form: {
  134. value: ''
  135. }
  136. },
  137. budget_startDate: {
  138. title: '开始日期',
  139. type: 'date',
  140. form: {
  141. show: compute(context => context.form.budget_policy === "dateRange"),
  142. rules: [{required: true, message:'必填项'}]
  143. }
  144. },
  145. budget_endDate: {
  146. title: '结束日期',
  147. type: 'date',
  148. form: {
  149. show: compute(context => context.form.budget_policy !== '')
  150. }
  151. },
  152. budget_amount: {
  153. title: '预算',
  154. type: 'number',
  155. form: {
  156. value: 0,
  157. show: compute(context => context.form.budget_policy !== ''),
  158. rules: [{required: true, message:'必填项'}],
  159. component: {
  160. min: 0,
  161. precision: 2,
  162. controlsPosition: "right"
  163. }
  164. }
  165. },
  166. inBudget: {
  167. title: '是否预算内',
  168. form: {
  169. show: false
  170. }
  171. },
  172. ...BaseColumn
  173. },
  174. },
  175. };
  176. };