diff --git a/web/src/i18n/pages/basicinfo/en.ts b/web/src/i18n/pages/basicinfo/en.ts index 3ed6e07..ecc3472 100644 --- a/web/src/i18n/pages/basicinfo/en.ts +++ b/web/src/i18n/pages/basicinfo/en.ts @@ -10,6 +10,10 @@ export default { unitnameEn: 'Unit Name (English)', unitnameZhTw: 'Unit Name (Traditional Chinese)', status: 'Status', + enabled: 'Enabled', + disabled: 'Disabled', + createTime: 'Create Time', + updateTime: 'Update Time', }, currency: { title: 'Currency', @@ -21,6 +25,10 @@ export default { currencynameEn: 'Currency Name (English)', currencynameZhTw: 'Currency Name (Traditional Chinese)', status: 'Status', + enabled: 'Enabled', + disabled: 'Disabled', + createTime: 'Create Time', + updateTime: 'Update Time', }, supplier: { title: 'Supplier Information', @@ -31,6 +39,8 @@ export default { vendorType: 'Vendor Type', paymentTerms: 'Payment Terms', transactionCurrency: 'Transaction Currency', + incoterms: 'Incoterms', + supplierLevel: 'Supplier Level', contactPerson: 'Contact Person', contactPhone: 'Contact Phone', contactEmail: 'Contact Email', @@ -38,7 +48,12 @@ export default { province: 'Province', city: 'City', address: 'Address', + postalCode: 'Postal Code', status: 'Status', + enabled: 'Enabled', + disabled: 'Disabled', + createTime: 'Create Time', + updateTime: 'Update Time', }, company: { title: 'Company Information', @@ -47,6 +62,8 @@ export default { companyShortName: 'Company Short Name', companyAddress: 'Company Address', status: 'Status', + createTime: 'Create Time', + updateTime: 'Update Time', }, emailnotice: { title: 'Email Notification Log', diff --git a/web/src/i18n/pages/basicinfo/zh-cn.ts b/web/src/i18n/pages/basicinfo/zh-cn.ts index 9ae968e..6397af9 100644 --- a/web/src/i18n/pages/basicinfo/zh-cn.ts +++ b/web/src/i18n/pages/basicinfo/zh-cn.ts @@ -10,6 +10,10 @@ export default { unitnameEn: '计量单位英文名', unitnameZhTw: '计量单位繁体名', status: '状态', + enabled: '可用', + disabled: '不可用', + createTime: '创建时间', + updateTime: '更新时间', }, currency: { title: '货币', @@ -21,6 +25,10 @@ export default { currencynameEn: '货币英文名', currencynameZhTw: '货币繁体名', status: '状态', + enabled: '可用', + disabled: '不可用', + createTime: '创建时间', + updateTime: '更新时间', }, supplier: { title: '供应商信息', @@ -31,6 +39,8 @@ export default { vendorType: '厂商性质', paymentTerms: '付款条件', transactionCurrency: '交易货币', + incoterms: '国际条款', + supplierLevel: '供应商等级', contactPerson: '联络人', contactPhone: '联络人电话', contactEmail: '联络人邮箱', @@ -38,7 +48,12 @@ export default { province: '省州', city: '城市', address: '详细地址', + postalCode: '邮政编码', status: '状态', + enabled: '可用', + disabled: '不可用', + createTime: '创建时间', + updateTime: '更新时间', }, company: { title: '公司信息', @@ -47,6 +62,8 @@ export default { companyShortName: '公司简称', companyAddress: '公司地址', status: '状态', + createTime: '创建时间', + updateTime: '更新时间', }, supplierUser: { title: '供应商用户', diff --git a/web/src/i18n/pages/basicinfo/zh-tw.ts b/web/src/i18n/pages/basicinfo/zh-tw.ts index 23ff171..642e146 100644 --- a/web/src/i18n/pages/basicinfo/zh-tw.ts +++ b/web/src/i18n/pages/basicinfo/zh-tw.ts @@ -10,6 +10,10 @@ export default { unitnameEn: '計量單位英文名', unitnameZhTw: '計量單位繁體名', status: '狀態', + enabled: '啟用', + disabled: '停用', + createTime: '創建時間', + updateTime: '更新時間', }, currency: { title: '貨幣', @@ -21,6 +25,10 @@ export default { currencynameEn: '貨幣英文名', currencynameZhTw: '貨幣繁體名', status: '狀態', + enabled: '啟用', + disabled: '停用', + createTime: '創建時間', + updateTime: '更新時間', }, supplier: { title: '供應商資訊', @@ -31,6 +39,8 @@ export default { vendorType: '廠商性質', paymentTerms: '付款條件', transactionCurrency: '交易貨幣', + incoterms: '國際條款', + supplierLevel: '供應商等級', contactPerson: '聯絡人', contactPhone: '聯絡人電話', contactEmail: '聯絡人郵箱', @@ -38,7 +48,12 @@ export default { province: '省州', city: '城市', address: '詳細地址', + postalCode: '郵遞區號', status: '狀態', + enabled: '啟用', + disabled: '停用', + createTime: '創建時間', + updateTime: '更新時間', }, company: { title: '公司資訊', @@ -47,6 +62,8 @@ export default { companyShortName: '公司簡稱', companyAddress: '公司地址', status: '狀態', + createTime: '創建時間', + updateTime: '更新時間', }, emailnotice: { title: '郵件通知記錄', diff --git a/web/src/views/pisadmin/basicinfo/company/crud.tsx b/web/src/views/pisadmin/basicinfo/company/crud.tsx index 0631f45..e9cd9d7 100644 --- a/web/src/views/pisadmin/basicinfo/company/crud.tsx +++ b/web/src/views/pisadmin/basicinfo/company/crud.tsx @@ -114,25 +114,25 @@ export const createCrudOptions = function ({ crudExpose }: Partial { - try { - const res = await api.GetCompanies({ page: 1, page_size: 1000, pageSize: 1000 }) - const list = - res?.data?.data?.results || - res?.data?.results || - res?.data?.list || - res?.data || - res?.results || - res?.list || - [] - return (Array.isArray(list) ? list : []).map((c: any) => ({ - company_code: c.company_code, - company_short_name: c.company_short_name || c.company_code || c.company_name - })) - } catch (e) { - console.warn('加载公司列表失败', e) - return [] - } -} - -// 预取一次,确保进入页面时就触发请求 -void loadCompanyOptions() - -export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet { +export const createCrudOptions = function ({ crudExpose }: Partial): CreateCrudOptionsRet { void crudExpose + const { t } = useI18n() + return { crudOptions: { form: { @@ -56,64 +30,80 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp }, columns: { currencyname: { - title: '货币名称', + title: t('message.pages.basicinfo.currency.currencyname'), type: 'input', - search: { show: true, component: { props: { placeholder: '请输入货币名称', clearable: true } } }, - form: { rules: [{ required: true, message: '请输入货币名称' }] }, + search: { show: true, component: { props: { placeholder: t('message.pages.basicinfo.currency.currencyname'), clearable: true } } }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.currency.currencyname') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 160, showOverflowTooltip: true } }, currencycode: { - title: '货币代码', + title: t('message.pages.basicinfo.currency.currencycode'), type: 'input', - search: { show: true, component: { props: { placeholder: '请输入货币代码', clearable: true } } }, - form: { rules: [{ required: true, message: '请输入货币代码' }] }, + search: { show: true, component: { props: { placeholder: t('message.pages.basicinfo.currency.currencycode'), clearable: true } } }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.currency.currencycode') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, editForm: { component: { props: { disabled: true } } }, column: { minWidth: 140, showOverflowTooltip: true } }, currencysymbol: { - title: '货币符号', + title: t('message.pages.basicinfo.currency.currencysymbol'), type: 'input', - form: { rules: [{ required: true, message: '请输入货币符号' }] }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.currency.currencysymbol') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { width: 120, showOverflowTooltip: true } }, factory: { - title: '交易厂区', + title: t('message.pages.basicinfo.currency.factory'), type: 'dict-select', dict: dict({ cache: false, value: 'company_code', label: 'company_short_name', getData: async () => { - return loadCompanyOptions() + try { + const res = await api.GetCompanies({ page: 1, page_size: 1000, pageSize: 1000 }) + const list = + res?.data?.data?.results || + res?.data?.results || + res?.data?.list || + res?.data || + res?.results || + res?.list || + [] + return (Array.isArray(list) ? list : []).map((c: any) => ({ + company_code: c.company_code, + company_short_name: c.company_short_name || c.company_code || c.company_name + })) + } catch (e) { + return [] + } } }), search: { show: true }, - form: { rules: [{ required: true, message: '请选择交易厂区' }] }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.currency.factory') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { width: 160, showOverflowTooltip: true } }, tax: { - title: '税率(%)', + title: t('message.pages.basicinfo.currency.tax') + '(%)', type: 'number', - form: { rules: [{ required: true, message: '请输入税率' }], component: { props: { precision: 2 } } }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.currency.tax') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }], component: { props: { precision: 2 } } }, column: { width: 120 } }, status: { - title: '可用状态', + title: t('message.pages.basicinfo.currency.status'), type: 'dict-switch', - dict: dict({ data: statusDict }), + dict: dict({ data: [{ value: 1, label: t('message.pages.basicinfo.currency.enabled') }, { value: 0, label: t('message.pages.basicinfo.currency.disabled') }] }), form: { value: 1 }, column: { width: 120 } }, create_datetime: { - title: '创建时间', + title: t('message.pages.basicinfo.currency.createTime'), type: 'datetime', form: { show: false }, column: { width: 180 } }, update_datetime: { - title: '更新时间', + title: t('message.pages.basicinfo.currency.updateTime'), type: 'datetime', form: { show: false }, column: { width: 180 } diff --git a/web/src/views/pisadmin/basicinfo/supplier/crud.tsx b/web/src/views/pisadmin/basicinfo/supplier/crud.tsx index 9462be0..8c46ecf 100644 --- a/web/src/views/pisadmin/basicinfo/supplier/crud.tsx +++ b/web/src/views/pisadmin/basicinfo/supplier/crud.tsx @@ -3,91 +3,55 @@ import * as api from './api' import { GetCompanies } from '../currency/api' import { GetList as GetCurrencies } from '../currency/api' import { ElMessage } from 'element-plus' +import { useI18n } from 'vue-i18n' -const statusDict = [ - { value: 1, label: '可用' }, - { value: 0, label: '不可用' } -] - -const vendorTypeDict = [ - { value: '国有', label: '国有' }, - { value: '集体', label: '集体' }, - { value: '私营', label: '私营' }, - { value: '合资', label: '合资' }, - { value: '独资', label: '独资' }, - { value: '其他', label: '其他' } -] - -const paymentTermDict = [ - { value: 'tt_30_70', label: 'T/T 30%预付,70%出货前' }, - { value: 'net30', label: '月结30天' }, - { value: 'net45', label: '月结45天' }, - { value: 'prepaid', label: '全额预付' } -] - -const incotermDict = [ - { value: 'EXW', label: 'EXW(工厂交货)' }, - { value: 'FCA', label: 'FCA(货交承运人)' }, - { value: 'CPT', label: 'CPT(运费付至)' }, - { value: 'CIP', label: 'CIP(运费及保险费付至)' }, - { value: 'DAP', label: 'DAP(目的地交货)' }, - { value: 'DPU', label: 'DPU(卸货地交货)' }, - { value: 'DDP', label: 'DDP(完税后交货)' }, - { value: 'FAS', label: 'FAS(船边交货)' }, - { value: 'FOB', label: 'FOB(船上交货)' }, - { value: 'CFR', label: 'CFR(成本加运费)' }, - { value: 'CIF', label: 'CIF(成本、保险费加运费)' } -] - -const loadCompanyOptions = async () => { - try { - const res = await GetCompanies({ page: 1, page_size: 1000, pageSize: 1000 }) - const list = - res?.data?.data?.results || - res?.data?.results || - res?.data?.list || - res?.data || - res?.results || - res?.list || - [] - return (Array.isArray(list) ? list : []).map((c: any) => ({ - company_code: c.company_code, - company_short_name: c.company_short_name || c.company_code || c.company_name - })) - } catch (e) { - console.warn('加载公司列表失败', e) - return [] - } -} - -const loadCurrencyOptions = async (companyCode?: string) => { - try { - const params: any = { page: 1, page_size: 500, pageSize: 500 } - if (companyCode) params.factory = companyCode - const res = await GetCurrencies(params) - const list = - res?.data?.data?.results || - res?.data?.results || - res?.data?.list || - res?.data || - res?.results || - res?.list || - [] - return (Array.isArray(list) ? list : []).map((c: any) => ({ - value: c.currencycode || c.currency_code, - label: c.currencyname || c.currency_code || c.currencycode || c.currency_name - })) - } catch (e) { - console.warn('加载币别列表失败', e) - return [] - } -} - -// 预取一次公司列表 -void loadCompanyOptions() - -export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet { +export const createCrudOptions = function ({ crudExpose }: Partial): CreateCrudOptionsRet { void crudExpose + const { t } = useI18n() + + const loadCompanyOptions = async () => { + try { + const res = await GetCompanies({ page: 1, page_size: 1000, pageSize: 1000 }) + const list = + res?.data?.data?.results || + res?.data?.results || + res?.data?.list || + res?.data || + res?.results || + res?.list || + [] + return (Array.isArray(list) ? list : []).map((c: any) => ({ + company_code: c.company_code, + company_short_name: c.company_short_name || c.company_code || c.company_name + })) + } catch (e) { + console.warn('Failed to load company list', e) + return [] + } + } + + const loadCurrencyOptions = async (companyCode?: string) => { + try { + const params: any = { page: 1, page_size: 500, pageSize: 500 } + if (companyCode) params.factory = companyCode + const res = await GetCurrencies(params) + const list = + res?.data?.data?.results || + res?.data?.results || + res?.data?.list || + res?.data || + res?.results || + res?.list || + [] + return (Array.isArray(list) ? list : []).map((c: any) => ({ + value: c.currencycode || c.currency_code, + label: c.currencyname || c.currency_code || c.currencycode || c.currency_name + })) + } catch (e) { + console.warn('Failed to load currency list', e) + return [] + } + } const ensureSupplierUnique = async (companyCode: string, supplierId: string, currentId?: number) => { if (!companyCode || !supplierId) return @@ -104,9 +68,13 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp ? list.find((item: any) => item.company_code === companyCode && item.supplier_id === supplierId) : null if (exists && (!currentId || exists.id !== currentId)) { - throw new Error('同一交易厂区下供应商代码已存在,不可重复') + throw new Error(t('message.pages.basicinfo.supplier.supplierId') + t('message.pages.menu.validation.alreadyExists')) } } + + // Pre-load company options + void loadCompanyOptions() + return { crudOptions: { form: { @@ -147,7 +115,7 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp }, columns: { company_code: { - title: '交易厂区', + title: t('message.pages.basicinfo.supplier.companyCode'), type: 'dict-select', dict: dict({ cache: false, @@ -157,11 +125,10 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp }), search: { show: true }, form: { - rules: [{ required: true, message: '请选择交易厂区' }], + rules: [{ required: true, message: t('message.pages.basicinfo.supplier.companyCode') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }], component: { on: { change({ form, value }: any) { - // 切换厂区时清空币别,触发重新加载 form.transaction_currency = undefined form.company_code = value } @@ -171,39 +138,51 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp column: { minWidth: 160, showOverflowTooltip: true } }, supplier_id: { - title: '供应商代码/ID', + title: t('message.pages.basicinfo.supplier.supplierId'), type: 'input', - search: { show: true, component: { props: { placeholder: '请输入供应商代码/ID', clearable: true } } }, - form: { rules: [{ required: true, message: '请输入供应商代码/ID' }] }, + search: { show: true, component: { props: { placeholder: t('message.pages.basicinfo.supplier.supplierId'), clearable: true } } }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.supplier.supplierId') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 140, showOverflowTooltip: true } }, supplier_name: { - title: '供应商全称', + title: t('message.pages.basicinfo.supplier.supplierName'), type: 'input', - search: { show: true, component: { props: { placeholder: '请输入供应商全称', clearable: true } } }, - form: { rules: [{ required: true, message: '请输入供应商全称' }] }, + search: { show: true, component: { props: { placeholder: t('message.pages.basicinfo.supplier.supplierName'), clearable: true } } }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.supplier.supplierName') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 180, showOverflowTooltip: true } }, supplier_short_name: { - title: '供应商简称', + title: t('message.pages.basicinfo.supplier.supplierShortName'), type: 'input', - form: { rules: [{ required: true, message: '请输入供应商简称' }] }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.supplier.supplierShortName') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 160, showOverflowTooltip: true } }, vendor_type: { - title: '厂商性质', + title: t('message.pages.basicinfo.supplier.vendorType'), type: 'dict-select', - dict: dict({ data: vendorTypeDict }), + dict: dict({ data: [ + { value: '国有', label: t('message.pages.pissupplier.vendorType.stateOwned') }, + { value: '集体', label: t('message.pages.pissupplier.vendorType.collective') }, + { value: '私营', label: t('message.pages.pissupplier.vendorType.private') }, + { value: '合资', label: t('message.pages.pissupplier.vendorType.joint') }, + { value: '独资', label: t('message.pages.pissupplier.vendorType.whollyOwned') }, + { value: '其他', label: t('message.pages.pissupplier.vendorType.other') }, + ] }), column: { minWidth: 140, showOverflowTooltip: true } }, payment_terms: { - title: '付款条件', + title: t('message.pages.basicinfo.supplier.paymentTerms'), type: 'dict-select', - dict: dict({ data: paymentTermDict }), + dict: dict({ data: [ + { value: 'tt_30_70', label: t('message.pages.pissupplier.paymentTerms.tt30_70') }, + { value: 'net30', label: t('message.pages.pissupplier.paymentTerms.net30') }, + { value: 'net45', label: t('message.pages.pissupplier.paymentTerms.net45') }, + { value: 'prepaid', label: t('message.pages.pissupplier.paymentTerms.prepaid') }, + ] }), column: { minWidth: 160, showOverflowTooltip: true } }, transaction_currency: { - title: '交易货币', + title: t('message.pages.basicinfo.supplier.transactionCurrency'), type: 'dict-select', dict: dict({ cache: false, @@ -215,77 +194,89 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp column: { minWidth: 140, showOverflowTooltip: true } }, incoterms: { - title: '国际条款', + title: t('message.pages.basicinfo.supplier.incoterms'), type: 'dict-select', - dict: dict({ data: incotermDict }), + dict: dict({ data: [ + { value: 'EXW', label: 'EXW' }, + { value: 'FCA', label: 'FCA' }, + { value: 'CPT', label: 'CPT' }, + { value: 'CIP', label: 'CIP' }, + { value: 'DAP', label: 'DAP' }, + { value: 'DPU', label: 'DPU' }, + { value: 'DDP', label: 'DDP' }, + { value: 'FAS', label: 'FAS' }, + { value: 'FOB', label: 'FOB' }, + { value: 'CFR', label: 'CFR' }, + { value: 'CIF', label: 'CIF' }, + ] }), column: { minWidth: 160, showOverflowTooltip: true } }, supplier_level: { - title: '供应商等级', + title: t('message.pages.basicinfo.supplier.supplierLevel'), type: 'input', column: { minWidth: 120, showOverflowTooltip: true } }, contact_person: { - title: '联络人', + title: t('message.pages.basicinfo.supplier.contactPerson'), type: 'input', - form: { rules: [{ required: true, message: '请输入联络人' }] }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.supplier.contactPerson') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 120, showOverflowTooltip: true } }, contact_phone: { - title: '联络人电话', + title: t('message.pages.basicinfo.supplier.contactPhone'), type: 'input', - form: { rules: [{ required: true, message: '请输入联络人电话' }] }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.supplier.contactPhone') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 140, showOverflowTooltip: true } }, contact_email: { - title: '联络人邮箱', + title: t('message.pages.basicinfo.supplier.contactEmail'), type: 'input', - form: { rules: [{ required: true, message: '请输入联络人邮箱' }] }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.supplier.contactEmail') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 180, showOverflowTooltip: true } }, country: { - title: '国家', + title: t('message.pages.basicinfo.supplier.country'), type: 'input', - form: { rules: [{ required: true, message: '请输入国家' }] }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.supplier.country') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 120, showOverflowTooltip: true } }, province: { - title: '省州', + title: t('message.pages.basicinfo.supplier.province'), type: 'input', - form: { rules: [{ required: true, message: '请输入省州' }] }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.supplier.province') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 120, showOverflowTooltip: true } }, city: { - title: '城市', + title: t('message.pages.basicinfo.supplier.city'), type: 'input', column: { minWidth: 120, showOverflowTooltip: true } }, address: { - title: '详细地址', + title: t('message.pages.basicinfo.supplier.address'), type: 'textarea', column: { minWidth: 200, showOverflowTooltip: true }, form: { component: { props: { rows: 2 } } } }, postal_code: { - title: '邮递区号', + title: t('message.pages.basicinfo.supplier.postalCode'), type: 'input', column: { minWidth: 120, showOverflowTooltip: true } }, status: { - title: '可用状态', + title: t('message.pages.basicinfo.supplier.status'), type: 'dict-switch', - dict: dict({ data: statusDict }), + dict: dict({ data: [{ value: 1, label: t('message.pages.basicinfo.supplier.enabled') }, { value: 0, label: t('message.pages.basicinfo.supplier.disabled') }] }), form: { value: 1 }, column: { width: 120 } }, create_datetime: { - title: '创建时间', + title: t('message.pages.basicinfo.supplier.createTime'), type: 'datetime', form: { show: false }, column: { width: 180 } }, update_datetime: { - title: '更新时间', + title: t('message.pages.basicinfo.supplier.updateTime'), type: 'datetime', form: { show: false }, column: { width: 180 } diff --git a/web/src/views/pisadmin/basicinfo/unit/crud.tsx b/web/src/views/pisadmin/basicinfo/unit/crud.tsx index 7ecdd45..7a8ab1a 100644 --- a/web/src/views/pisadmin/basicinfo/unit/crud.tsx +++ b/web/src/views/pisadmin/basicinfo/unit/crud.tsx @@ -1,31 +1,10 @@ import { dict, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud' import * as api from './api' -import { ElMessage } from 'element-plus' +import { useI18n } from 'vue-i18n' -const statusDict = [ - { value: 1, label: '可用' }, - { value: 0, label: '不可用' } -] - -export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet { +export const createCrudOptions = function ({ crudExpose }: Partial): CreateCrudOptionsRet { void crudExpose - - const ensureUnitCodeUnique = async (code: string, currentId?: number) => { - if (!code) return - const res = await api.GetList({ unitcode: code, page: 1, page_size: 1, pageSize: 1 }) - const list = - res?.data?.data?.results || - res?.data?.results || - res?.data?.list || - res?.data || - res?.results || - res?.list || - [] - const exists = Array.isArray(list) ? list.find((item: any) => item.unitcode === code) : null - if (exists && (!currentId || exists.id !== currentId)) { - throw new Error('计量单位代码已存在,不可重复') - } - } + const { t } = useI18n() return { crudOptions: { @@ -34,24 +13,8 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp }, request: { pageRequest: async (query) => api.GetList(query), - addRequest: async ({ form }) => { - try { - await ensureUnitCodeUnique(form.unitcode) - return await api.AddObj(form) - } catch (err: any) { - ElMessage.error(err?.message || '保存失败') - throw err - } - }, - editRequest: async ({ form, row }) => { - try { - await ensureUnitCodeUnique(form.unitcode, row.id) - return await api.UpdateObj({ ...form, id: row.id }) - } catch (err: any) { - ElMessage.error(err?.message || '保存失败') - throw err - } - }, + addRequest: async ({ form }) => api.AddObj(form), + editRequest: async ({ form, row }) => api.UpdateObj({ ...form, id: row.id }), delRequest: async ({ row }) => api.DelObj(row.id) }, table: { @@ -67,35 +30,34 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp }, columns: { unitcode: { - title: '计量单位代码', + title: t('message.pages.basicinfo.unit.unitcode'), type: 'input', - search: { show: true, component: { props: { placeholder: '请输入计量单位代码', clearable: true } } }, - form: { rules: [{ required: true, message: '请输入计量单位代码' }] }, + search: { show: true, component: { props: { placeholder: t('message.pages.basicinfo.unit.unitcode'), clearable: true } } }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.unit.unitcode') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 140, showOverflowTooltip: true } }, unitname: { - title: '计量单位名称', + title: t('message.pages.basicinfo.unit.unitname'), type: 'input', - search: { show: true, component: { props: { placeholder: '请输入计量单位名称', clearable: true } } }, - form: { rules: [{ required: true, message: '请输入计量单位名称' }] }, + search: { show: true, component: { props: { placeholder: t('message.pages.basicinfo.unit.unitname'), clearable: true } } }, + form: { rules: [{ required: true, message: t('message.pages.basicinfo.unit.unitname') + ' ' + t('message.pages.menu.validation.fieldNameRequired') }] }, column: { minWidth: 160, showOverflowTooltip: true } }, - status: { - title: '可用状态', + title: t('message.pages.basicinfo.unit.status'), type: 'dict-switch', - dict: dict({ data: statusDict }), + dict: dict({ data: [{ value: 1, label: t('message.pages.basicinfo.unit.enabled') }, { value: 0, label: t('message.pages.basicinfo.unit.disabled') }] }), form: { value: 1 }, column: { width: 120 } }, create_datetime: { - title: '创建时间', + title: t('message.pages.basicinfo.unit.createTime'), type: 'datetime', form: { show: false }, column: { width: 180 } }, update_datetime: { - title: '更新时间', + title: t('message.pages.basicinfo.unit.updateTime'), type: 'datetime', form: { show: false }, column: { width: 180 }