123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- import { AddReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, uiContext, UserPageQuery } from '@fast-crud/fast-crud';
- import dayjs from 'dayjs';
- import * as api from './api';
- import { uploadFile } from './api';
- import { auth } from '/@/utils/authFunction';
- import { commonCrudConfig } from '/@/utils/commonCrud';
- import {request} from '/@/utils/service';
- import {getBaseURL} from '/@/utils/baseUrl';
- import Cookies from 'js-cookie';
- import { successMessage } from '/@/utils/message';
- import { dictionary } from '/@/utils/dictionary';
- import { APIResponseData } from '../columns/types';
- export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
- const pageRequest = async (query: UserPageQuery) => {
- return await api.GetList(query);
- };
- const editRequest = async ({ form, row }: EditReq) => {
- form.id = row.id;
- return await api.UpdateObj(form);
- };
- const delRequest = async ({ row }: DelReq) => {
- return await api.DelObj(row.id);
- };
- const addRequest = async ({ form }: AddReq) => {
- return await api.AddObj(form);
- };
-
- const ui = uiContext.get();
- return {
- crudOptions: {
- request: {
- pageRequest,
- addRequest,
- editRequest,
- delRequest,
- },
- toolbar:{
- show:false,
- },
- rowHandle: {
- fixed: 'right',
- width: 220,
- view: {
- show: true,
- click: ({ row }) => {
- window.dispatchEvent(new CustomEvent('workflow-view', { detail: row }));
- },
- },
- edit: {
- show: true,
- click: ({ row }) => {
- window.dispatchEvent(new CustomEvent('workflow-edit', { detail: row }));
- },
- },
- remove: {
- show: true,
- },
- },
- actionbar: {
- buttons: {
- add: {
- show: auth('user:Create')
- },
- batchimport:{
- text: "批量导入",//按钮文字
- title: "导入",//鼠标停留显示的信息
- // show: auth('user:batchimport'),
- },
- export: {
- text: "导出",//按钮文字
- title: "导出",//鼠标停留显示的信息
- show: auth('user:Export'),
- },
- downloadtemplate: {
- text: "下载模板",//按钮文字
- title: "下载模板",//鼠标停留显示的信息
- // show: auth('user:Export'),
- },
- batchdelete: {
- text: "批量删除",//按钮文字
- title: "批量删除",//鼠标停留显示的信息
- // show: auth('user:Export'),
- },
- }
- },
- columns: {
- _index: {
- title: '序号',
- form: { show: false },
- column: {
- align: 'center',
- width: '70px',
- columnSetDisabled: true,
- formatter: (context) => {
- let index = context.index ?? 1;
- let pagination = crudExpose!.crudBinding.value.pagination;
- return ((pagination!.currentPage ?? 1) - 1) * pagination!.pageSize + index + 1;
- },
- },
- },
- code: {
- title: '设备编号',
- search: { show: true },
- type: 'input',
- column: { minWidth: 120 },
- form: {
- component: { placeholder: '请输入设备编号' },
- rules: [{ required: true, message: '请输入设备编号' }],
- },
- },
-
- category_name: {
- title: '设备分类',
- search: { show: true },
- type: 'dict-select',
- dict: dict({
- url: '/api/system/device/category/',
- value: 'id',
- label: 'name',
- }),
- column: { minWidth: 100 },
- form: {
- show:false,
- component: { placeholder: '请选择设备分类' },
- rules: [{ required: true, message: '请选择设备分类' }],
- },
- },
- name: {
- title: '设备名称',
- search: { show: false },
- type: 'input',
- column: { minWidth: 120 },
- form: {
- component: { placeholder: '请输入设备名称' },
- rules: [{ required: true, message: '请输入设备名称' }]
- }
- },
- // statusss: {
- // title: '设备状态',
- // type: 'dict-select',
- // search: { show: false },
- // dict: dict({
- // data: [
- // { label: '在借', value: 1 },
- // { label: '空闲', value: 2 },
- // ],
- // }),
- // column: { minWidth: 100 },
- // form: {
- // component: { placeholder: '请选择设备状态' },
- // rules: [{ required: true, message: '请选择设备状态' }],
- // },
- // },
- "inventory.borrowed_quantity":{
- title: '设备状态',
- type: 'dict-select',
- search: { show: false },
- dict: dict({
- data: [
- { label: '在借', value: 1 },
- { label: '空闲', value: 0 },
- ],
- getData: (dict) => {
- return (value) => {
- return value > 0 ? '在借' : '空闲';
- }
- }
- }),
- column: { show:true, minWidth: 100 },
- form: {
- show:false,
- component: { placeholder: '请选择设备状态' },
- rules: [{ required: true, message: '请选择设备状态' }],
- },
- },
- borrowed_quantity:{
- title:"已借出",
- type:'input',
- search:{show:false},
- column: { minWidth: 100 },
- form: {
- show:false,
- component: { placeholder: '请输入已借出' },
- rules: [{ required: true, message: '请输入已借出' }],
- },
- },
- brand:{
- title:'品牌',
- type:"input",
- column: { minWidth: 100 },
- },
- specification: {
- title: '规格型号',
- search: { show: false },
- type: 'input',
- column: { minWidth: 100 },
- form: {
- component: { placeholder: '请输入规格型号' }
- }
- },
- serial_number:{
- title:'序列号',
- type:"input",
- column: { minWidth: 100 },
- },
- total_quantity:{
- title:'库存数量',
- type:"input",
- column: { minWidth: 100 },
- addForm:{
- show:false,
- },
- viewForm:{
- show:false,
- },
- editForm:{show:false},
- from:{
- show:false,
- component: { placeholder: '请输入已借出' },
- rules: [{ required: true, message: '请输入已借出' }],
- }
- },
- warehouse:{
- title:'库存仓库',
- type:"dict-select",
- column: { minWidth: 150 },
- dict: dict({
- url: '/api/system/warehouse/',
- value: 'id',
- label: 'name'
- }),
- form: {
- component: { placeholder: '请选择库存仓库' }
- }
- },
- status:{
- title:'是否可见',
- type: 'dict-switch',
- column: {
- minWidth: 90,
- component: {
- name: 'fs-dict-switch',
- activeText: '',
- inactiveText: '',
- style: '--el-switch-on-color: var(--el-color-primary); --el-switch-off-color: #dcdfe6',
- onChange: compute((context) => {
- return () => {
- api.UpdateObjStatus(context.row).then((res:APIResponseData) => {
- successMessage(res.msg as string);
- });
- };
- }),
- },
- },
- dict: dict({
- data: dictionary('device_button_status_bool'),
- }),
- },
-
- department: {
- title: '所属部门',
- search: { show: false },
- type: 'input',
- column: { minWidth: 120 },
- form: {
- component: { placeholder: '请输入所属部门' }
- }
- },
- purchase_date: {
- title: '采购时间',
- type: 'date',
- search: { show: false },
- column: {
- minWidth: 120,
- formatter: ({ value }) => (value ? dayjs(value).format('YYYY-MM-DD') : ''),
- },
- form: {
- component: { placeholder: '请选择购买日期' },
- rules: [{ required: true, message: '请选择购买日期' }],
- },
- valueResolve({ form, value }) {
- form.purchase_date = value ? dayjs(value).format('YYYY-MM-DD') : null;
- },
- valueBuilder({ form, value }) {
- form.purchase_date = value;
- },
- },
-
- supplier: {
- title: '供应商',
- type: 'dict-select',
- search: { show: false },
- column: {
- minWidth: 120,
- },
- dict: dict({
- url: '/api/system/supplier/',
- value: 'id',
- label: 'name'
- }),
- form: {
- component: { placeholder: '请输入供应商' },
- },
- },
- price: {
- title: '价格',
- type: 'number',
- search: { show: false },
- column: { minWidth: 100 },
- form: {
- component: { placeholder: '请输入设备购入价格' },
- rules: [{ required: true, message: '请输入设备购入价格' }],
- },
- },
- warranty_expiration: {
- title: '保质期',
- type: 'date',
- search: { show: false },
- column: { minWidth: 120 ,
- formatter: ({ value }) => (value ? dayjs(value).format('YYYY-MM-DD') : ''),
- },
- form: {
- component: { placeholder: '请选择购买日期' },
- rules: [{ required: true, message: '请选择购买日期' }],
- },
- valueResolve({ form, value }) {
- form.warranty_expiration = value ? dayjs(value).format('YYYY-MM-DD') : null;
- },
- valueBuilder({ form, value }) {
- form.warranty_expiration = value;
- },
- },
- image:{
- title: '设备图片',
- type: 'image-uploader',
- column: {
- minWidth: 120,
- show:false,
- },
- form: {
- show: auth('image:upload'),
- component: {
- uploader: {
- type: 'form',
- limit: 1,
- action: '/api/system/device/upload-image/',
- accept: ".jpg,.png",
- uploadRequest: async ({ action, file, onProgress }) => {
- const token = Cookies.get('token');
- // eslint-disable-next-line no-console
- console.log("token:::",token);
- const data = new FormData();
- data.append("image", file);
- return await request({
- url: action,
- method: "post",
- timeout: 60000,
- headers: {
- "Content-Type": "multipart/form-data",
- "Authorization": token ? `JWT ${token}` : ''
- },
- data,
- onUploadProgress: (p) => {
- onProgress({ percent: Math.round((p.loaded / p.total) * 100) });
- }
- });
- },
- successHandle(ret) {
- // eslint-disable-next-line no-console
- console.log("ret.data.image_url:::",ret.data.image_url);
- return {
- url: getBaseURL(ret.data.image_url),
- key: ret.data.id,
- ...ret.data
- };
- },
-
-
-
- }
- },
-
- },
- valueBuilder({ row, key }) {
- return row[key] ? [row[key]] : [];
- },
- valueResolve({ form, key }) {
- // eslint-disable-next-line no-console
- console.log("form[key]:::",form[key]);
- form[key] = Array.isArray(form[key]) ? form[key][0] : form[key];
- }
- // form: {
- // // component: { placeholder: '请上传图片' },
- // component: {
- // limit: 1,
- // uploader: {
- // type: "form"
- // }
- // },
- // rules: createUploaderRules([{ required: true, message: "此项必传", trigger: "change" }]),
- // change:()=>{
- // },
- // helper: "上传设备图片",
- // },
-
-
- },
- tenant_id:{
- title: '租户id',
- type: 'dict-select',
- column: {
- show:false,
- minWidth: 120,
- },
- dict: dict({
- url: '/api/system/tenant/list/',
- value: 'id',
- label: 'name'
- }),
- form: {
- component: { placeholder: '请填租户id' },
- rules: [{ required: false, message: '请填租户id' }],
- },
- },
- category:{
- show: false,
- title: '类别id',
- search: { show: false },
- type: 'dict-select',
- column: { show: false,minWidth: 120 },
- dict: dict({
- url: '/api/system/device/category/',
- value: 'id',
- label: 'name'
- }),
- form: {
- component: { placeholder: '请输入类别id' }
- }
- },
- quantity:{
- show: false,
- title: '库存数量',
- search: { show: false },
- type: 'input',
- column: { show: false,minWidth: 120 },
- form: {
- component: { placeholder: '请输入库存数量' }
- }
- },
- tags:{
- show: false,
- title: '设备标签',
- search: { show: false },
- type: 'dict-select',
- column: { show: false,minWidth: 120 },
- dict: dict({
- url: '/api/system/device_tags/',
- value: 'id',
- label: 'name'
- }),
- form: {
- component: { placeholder: '请选择设备标签' },
- valueResolve({ form, value }) {
- form.tags = Array.from(String(value), Number);
- },
- valueBuilder({ form, value }) {
- form.tags =Array.from(String(value), Number);
- },
- }
- },
- // maintenancename: {
- // title: '维修名称',
- // type: 'input',
- // search: { show: false },
- // column: { show:false,minWidth: 100 },
- // form: {
- // component: { placeholder: '请输入设备购入价格' },
- // rules: [{ required: true, message: '请输入设备购入价格' }],
- // },
- // },
- ...commonCrudConfig({
- create_datetime: { search: false },
- update_datetime: { search: false },
- }),
- },
- form: {
- row: { gutter: 20 },
- group: {
- groupType: "tabs", //collapse, tabs
- accordion: false,
- groups: {
- base: {
- slots: {
- label: (scope) => {
- return (
- <span style={{ color: scope.hasError ? "red" : "green" }}>
- <fs-icon icon={"ion:checkmark-circle"} />
- 基础信息
- </span>
- );
- }
- },
- icon: "el-icon-goods",
- columns: ["code","category_name", "name", "status","borrowed_quantity","brand","specification","serial_number","warehouse","is_visible","department","purchase_date","supplier","price","warranty_expiration","image","tenant_id","category","quantity","tags"]
- },
- borrow: {
- label: "借用记录",
- icon: "el-icon-price-tag",
- columns: []
- },
- maintenance: {
- label: "维修记录",
- collapsed: true, //默认折叠
- icon: "el-icon-warning-outline",
- columns: [""]
- },
- maintain: {
- label: "保养记录",
- collapsed: true, //默认折叠
- icon: "el-icon-warning-outline",
- columns: []
- },
- datastatis: {
- label: "数据统计",
- collapsed: true, //默认折叠
- icon: "el-icon-warning-outline",
- columns: []
- },
- }
- }
- },
- },
- };
- };
|