crud.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import { AddReq, CreateCrudOptionsProps, dict,CreateCrudOptionsRet, UserPageQuery,compute } from '@fast-crud/fast-crud';
  2. import * as api from './api';
  3. import { auth } from '/@/utils/authFunction';
  4. import dayjs from 'dayjs';
  5. import { Ref } from 'vue';
  6. import axios from 'axios';
  7. import { successMessage,warningMessage } from '/@/utils/message';
  8. import { Session } from '/@/utils/storage';
  9. export const createCrudOptions = function ({ crudExpose , inventoryDialog}: CreateCrudOptionsProps& { inventoryDialog: Ref<any> }): CreateCrudOptionsRet {
  10. const pageRequest = async (query: UserPageQuery) => {
  11. return await api.GetList(query);
  12. };
  13. const editRequest = async ({ form, row }: EditReq) => {
  14. form.id = row.id;
  15. return await api.UpdateObj(form);
  16. };
  17. const delRequest = async ({ row }: DelReq) => {
  18. return await api.DelObj(row.id);
  19. };
  20. const addRequest = async ({ form }: AddReq) => {
  21. return await api.AddObj(form);
  22. };
  23. return {
  24. crudOptions: {
  25. request: {
  26. pageRequest,
  27. addRequest,
  28. editRequest,
  29. delRequest,
  30. },
  31. form:{
  32. wrapper: {
  33. buttons: {
  34. ok:{
  35. text:'提交',
  36. show:compute((row) => {
  37. return row.mode !=='view'
  38. })
  39. }
  40. }
  41. }
  42. },
  43. actionbar: {
  44. buttons: {
  45. add: {
  46. show: false,
  47. },
  48. startTaking: {
  49. text: '开始盘点',
  50. // icon: 'el-icon-document',
  51. click: async () => {
  52. const res =await api.StartScan({ remark: '例行盘点' });
  53. if (res?.code === 2000) {
  54. inventoryDialog.value.setCheckNo(res.data.check_no);
  55. inventoryDialog.value.visible = true;
  56. }
  57. },
  58. },
  59. },
  60. },
  61. toolbar:{
  62. show:true,
  63. },
  64. rowHandle:{
  65. fixed: 'right',
  66. width: 220,
  67. buttons:{
  68. view:{
  69. show:false
  70. },
  71. remove:{
  72. show:false,
  73. },
  74. edit:{
  75. show:false,
  76. },
  77. reanalyze: { // 添加重新分析按钮
  78. text: '取消',
  79. iconRight: '',
  80. type:'danger',
  81. show:compute(({ row }) => {
  82. return row.status === 0; // 只在状态为"已面试"时显示
  83. }),
  84. order: 2,
  85. click: async ({ row }) => {
  86. try {
  87. // 先调用视频分析接口
  88. const videoAnalysisResponse = await axios.post(`${import.meta.env.VITE_API_URL}/api/system/inventory/check-records/${row.id}/cancel/`,{},{
  89. headers: {
  90. 'authorization':`JWT ${Session.get('token')}`
  91. }
  92. });
  93. console.log(videoAnalysisResponse);
  94. if (videoAnalysisResponse.data.code == 2000) {
  95. successMessage(videoAnalysisResponse.data.msg || "盘点已取消");
  96. crudExpose.doSearch()
  97. return;
  98. }
  99. /*// 视频分析成功后,调用综合分析接口
  100. const response = await axios.post(`${import.meta.env.VITE_API_URL}/api/system/job/trigger_comprehensive_analysis`, {
  101. application_id: row.id,
  102. force_trigger: true
  103. });
  104. if (response.data.code === 2000) {
  105. successMessage('取消成功');
  106. // 刷新当前页面数据
  107. crudExpose.doRefresh();
  108. } else {
  109. warningMessage(response.data.message || '取消成失败');
  110. } */
  111. } catch (error) {
  112. console.error('取消失败:', error);
  113. warningMessage('取消失败');
  114. }
  115. }
  116. },
  117. }
  118. },
  119. pagination: {
  120. show: true,
  121. },
  122. columns: {
  123. _index: {
  124. title: '序号',
  125. form: { show: false },
  126. column: {
  127. type: 'index',
  128. align: 'center',
  129. width: '70px',
  130. columnSetDisabled: true, //禁止在列设置中选择
  131. },
  132. },
  133. check_no: {
  134. title: '编号',
  135. search: {
  136. show: true,
  137. },
  138. treeNode: true,
  139. type: 'input',
  140. column: {
  141. minWidth: 120,
  142. },
  143. form: {
  144. show:true,
  145. rules: [
  146. // 表单校验规则
  147. { required: true, message: '名称必填项' },
  148. ],
  149. component: {
  150. placeholder: '请输入',
  151. },
  152. },
  153. viewForm:{
  154. component: { placeholder: '' },
  155. rules: [{ required: true, message: '' }],
  156. }
  157. },
  158. start_time:{
  159. title: '维护日期',
  160. type: 'datetime',
  161. column: {
  162. minWidth: 120,
  163. // formatter: ({ value }) => (value ? dayjs(value).format('YYYY-MM-DD') : ''),
  164. },
  165. form: {
  166. show:false,
  167. component: { placeholder: '请填写维护日期' },
  168. rules: [{ required: true, message: '请填写维护日期' }],
  169. },
  170. viewForm:{
  171. component: { placeholder: '' },
  172. rules: [{ required: true, message: '' }],
  173. },
  174. valueResolve({ form, value }) {
  175. form.start_time = value ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : null;
  176. },
  177. // valueBuilder({ form, value }) {
  178. // console.log("valuessss::",value)
  179. // form.start_time = value ;
  180. // },
  181. },
  182. checker_name:{
  183. title: '盘点人',
  184. type: 'input',
  185. column: {
  186. minWidth: 120,
  187. },
  188. form: {
  189. show:false,
  190. component: { placeholder: '请填写盘点人' },
  191. rules: [{ required: false, message: '请填写盘点人' }],
  192. },
  193. viewForm:{
  194. component: { placeholder: '' },
  195. rules: [{ required: false, message: '' }],
  196. }
  197. },
  198. status_display: {
  199. title: '状态',
  200. search: {
  201. show: false,
  202. },
  203. treeNode: true,
  204. type: 'input',
  205. column: {
  206. minWidth: 120,
  207. },
  208. form: {
  209. show:false,
  210. rules: [
  211. // 表单校验规则
  212. { required: true, message: '维护标题必填项' },
  213. ],
  214. component: {
  215. placeholder: '请输入维护标题',
  216. },
  217. },
  218. viewForm:{
  219. component: { placeholder: '' },
  220. rules: [{ required: true, message: '' }],
  221. }
  222. },
  223. },
  224. },
  225. };
  226. };