¶Ô±ÈÐÂÎļþ |
| | |
| | | // 设å¤åç管ç - æ¬å°åæ°æ® APIï¼ä½¿ç¨ localStorage æä¹
åï¼ |
| | | |
| | | const STORAGE_KEY = 'EQUIPMENT_BRANDS'; |
| | | |
| | | function readStore() { |
| | | try { |
| | | const raw = localStorage.getItem(STORAGE_KEY); |
| | | if (raw) { |
| | | const parsed = JSON.parse(raw); |
| | | if (Array.isArray(parsed)) return parsed; |
| | | } |
| | | } catch (e) { |
| | | // ignore |
| | | } |
| | | // åå§åä¸äºç¤ºä¾æ°æ® |
| | | const initial = [ |
| | | { id: 1, name: '西é¨å', country: 'å¾·å½', description: 'å·¥ä¸èªå¨åä¸çµæ°å·¥ç¨åç', createdAt: Date.now() - 86400000 * 10 }, |
| | | { id: 2, name: 'æ½èå¾·', country: 'æ³å½', description: 'è½æºç®¡çä¸èªå¨å', createdAt: Date.now() - 86400000 * 7 }, |
| | | { id: 3, name: 'ä¸è±çµæº', country: 'æ¥æ¬', description: 'çµæ°ä¸èªå¨å设å¤', createdAt: Date.now() - 86400000 * 3 }, |
| | | ]; |
| | | localStorage.setItem(STORAGE_KEY, JSON.stringify(initial)); |
| | | return initial; |
| | | } |
| | | |
| | | function writeStore(list) { |
| | | localStorage.setItem(STORAGE_KEY, JSON.stringify(list)); |
| | | } |
| | | |
| | | function nextId(list) { |
| | | const maxId = list.reduce((max, item) => Math.max(max, Number(item.id) || 0), 0); |
| | | return maxId + 1; |
| | | } |
| | | |
| | | export function getBrandPage(params = {}) { |
| | | const { current = 1, size = 10, name } = params; |
| | | const list = readStore(); |
| | | let filtered = list; |
| | | if (name) { |
| | | const kw = String(name).trim(); |
| | | filtered = filtered.filter((b) => |
| | | (b.name && b.name.includes(kw)) || (b.country && b.country.includes(kw)) |
| | | ); |
| | | } |
| | | const start = (current - 1) * size; |
| | | const end = start + Number(size); |
| | | const records = filtered.slice(start, end); |
| | | return Promise.resolve({ |
| | | code: 200, |
| | | data: { |
| | | total: filtered.length, |
| | | records, |
| | | }, |
| | | msg: 'ok', |
| | | }); |
| | | } |
| | | |
| | | export function getBrandById(id) { |
| | | const list = readStore(); |
| | | const item = list.find((i) => String(i.id) === String(id)); |
| | | return Promise.resolve({ code: 200, data: item || null, msg: 'ok' }); |
| | | } |
| | | |
| | | export function addBrand(data) { |
| | | const list = readStore(); |
| | | const item = { ...data }; |
| | | item.id = nextId(list); |
| | | item.createdAt = Date.now(); |
| | | list.unshift(item); |
| | | writeStore(list); |
| | | return Promise.resolve({ code: 200, data: item, msg: 'æ°å¢æå' }); |
| | | } |
| | | |
| | | export function editBrand(data) { |
| | | const list = readStore(); |
| | | const index = list.findIndex((i) => String(i.id) === String(data.id)); |
| | | if (index !== -1) { |
| | | list[index] = { ...list[index], ...data }; |
| | | writeStore(list); |
| | | return Promise.resolve({ code: 200, data: list[index], msg: 'ä¿®æ¹æå' }); |
| | | } |
| | | return Promise.resolve({ code: 404, data: null, msg: 'æªæ¾å°è¯¥åç' }); |
| | | } |
| | | |
| | | export function delBrand(idOrIds) { |
| | | const list = readStore(); |
| | | const ids = Array.isArray(idOrIds) ? idOrIds.map(String) : [String(idOrIds)]; |
| | | const newList = list.filter((i) => !ids.includes(String(i.id))); |
| | | writeStore(newList); |
| | | return Promise.resolve({ code: 200, data: null, msg: 'å 餿å' }); |
| | | } |
| | | |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <el-form :model="filters" :inline="true"> |
| | | <el-form-item label="åçåç§°/å½å®¶"> |
| | | <el-input |
| | | v-model="filters.name" |
| | | style="width: 240px" |
| | | placeholder="请è¾å
¥å
³é®è¯" |
| | | clearable |
| | | prefix-icon="Search" |
| | | @change="getTableData" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" @click="getTableData">æç´¢</el-button> |
| | | <el-button @click="resetFilters">éç½®</el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | |
| | | <div class="table_list"> |
| | | <div class="actions"> |
| | | <div></div> |
| | | <div> |
| | | <el-button type="primary" @click="openAdd" icon="Plus"> æ°å¢ </el-button> |
| | | <el-button |
| | | type="danger" |
| | | icon="Delete" |
| | | :disabled="multipleSelection.length <= 0" |
| | | @click="handleBatchDelete" |
| | | >æ¹éå é¤</el-button> |
| | | </div> |
| | | </div> |
| | | |
| | | <PIMTable |
| | | rowKey="id" |
| | | isSelection |
| | | :column="columns" |
| | | :tableData="dataList" |
| | | :page="{ |
| | | current: pagination.currentPage, |
| | | size: pagination.pageSize, |
| | | total: pagination.total, |
| | | }" |
| | | @selection-change="handleSelectionChange" |
| | | @pagination="changePage" |
| | | > |
| | | </PIMTable> |
| | | </div> |
| | | |
| | | <el-dialog v-model="visible" :title="dialogTitle" width="520px" destroy-on-close> |
| | | <el-form :model="form" ref="formRef" :rules="rules" label-width="90px"> |
| | | <el-form-item label="åçåç§°" prop="name"> |
| | | <el-input v-model="form.name" placeholder="请è¾å
¥åçåç§°" /> |
| | | </el-form-item> |
| | | <el-form-item label="æå±å½å®¶" prop="country"> |
| | | <el-input v-model="form.country" placeholder="请è¾å
¥å½å®¶/å°åº" /> |
| | | </el-form-item> |
| | | <el-form-item label="æè¿°" prop="description"> |
| | | <el-input v-model="form.description" type="textarea" :rows="3" placeholder="å¯å¡«ååçç®ä»" /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | | <el-button @click="visible = false">åæ¶</el-button> |
| | | <el-button type="primary" @click="handleSubmit">ç¡®å®</el-button> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, getCurrentInstance, onMounted } from 'vue' |
| | | import { ElMessageBox, ElMessage } from 'element-plus' |
| | | import { usePaginationApi } from '@/hooks/usePaginationApi' |
| | | import { getBrandPage, addBrand, editBrand, delBrand } from '@/api/equipmentManagement/brand' |
| | | |
| | | defineOptions({ name: '设å¤åç管ç' }) |
| | | |
| | | const { proxy } = getCurrentInstance() |
| | | |
| | | const multipleSelection = ref([]) |
| | | const formRef = ref() |
| | | const visible = ref(false) |
| | | const dialogTitle = ref('æ°å¢åç') |
| | | const form = ref({ id: undefined, name: '', country: '', description: '' }) |
| | | |
| | | const rules = { |
| | | name: [{ required: true, message: '请è¾å
¥åçåç§°', trigger: 'blur' }], |
| | | country: [{ required: true, message: '请è¾å
¥æå±å½å®¶', trigger: 'blur' }] |
| | | } |
| | | |
| | | const { |
| | | filters, |
| | | columns, |
| | | dataList, |
| | | pagination, |
| | | getTableData, |
| | | resetFilters, |
| | | onCurrentChange, |
| | | } = usePaginationApi( |
| | | getBrandPage, |
| | | { name: undefined }, |
| | | [ |
| | | { label: 'åçåç§°', align: 'center', prop: 'name' }, |
| | | { label: 'æå±å½å®¶', align: 'center', prop: 'country' }, |
| | | { label: 'æè¿°', align: 'center', prop: 'description' }, |
| | | { label: 'å建æ¶é´', align: 'center', prop: 'createdAt' }, |
| | | { |
| | | dataType: 'action', |
| | | label: 'æä½', |
| | | align: 'center', |
| | | fixed: 'right', |
| | | width: 140, |
| | | operation: [ |
| | | { |
| | | name: 'ç¼è¾', |
| | | type: 'text', |
| | | clickFun: (row) => openEdit(row), |
| | | }, |
| | | { |
| | | name: 'å é¤', |
| | | type: 'text', |
| | | clickFun: (row) => handleDelete(row.id), |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | ) |
| | | |
| | | const handleSelectionChange = (list) => { |
| | | multipleSelection.value = list |
| | | } |
| | | |
| | | const changePage = ({ page, limit }) => { |
| | | pagination.currentPage = page |
| | | pagination.pageSize = limit |
| | | onCurrentChange(page) |
| | | } |
| | | |
| | | function resetForm() { |
| | | form.value = { id: undefined, name: '', country: '', description: '' } |
| | | } |
| | | |
| | | function openAdd() { |
| | | resetForm() |
| | | dialogTitle.value = 'æ°å¢åç' |
| | | visible.value = true |
| | | } |
| | | |
| | | function openEdit(row) { |
| | | form.value = { id: row.id, name: row.name, country: row.country, description: row.description } |
| | | dialogTitle.value = 'ç¼è¾åç' |
| | | visible.value = true |
| | | } |
| | | |
| | | function handleSubmit() { |
| | | formRef.value.validate(async (valid) => { |
| | | if (!valid) return |
| | | const isEdit = Boolean(form.value.id) |
| | | const api = isEdit ? editBrand : addBrand |
| | | const { code, msg } = await api({ ...form.value }) |
| | | if (code === 200) { |
| | | ElMessage.success(isEdit ? 'ä¿®æ¹æå' : 'æ°å¢æå') |
| | | visible.value = false |
| | | getTableData() |
| | | } else { |
| | | ElMessage.error(msg || 'æä½å¤±è´¥') |
| | | } |
| | | }) |
| | | } |
| | | |
| | | function handleDelete(id) { |
| | | ElMessageBox.confirm('æ¤æä½å°æ°¸ä¹
å é¤è¯¥åç, æ¯å¦ç»§ç»?', 'æç¤º', { |
| | | confirmButtonText: 'ç¡®å®', |
| | | cancelButtonText: 'åæ¶', |
| | | type: 'warning', |
| | | }).then(async () => { |
| | | const { code } = await delBrand(id) |
| | | if (code === 200) { |
| | | ElMessage.success('å 餿å') |
| | | getTableData() |
| | | } |
| | | }) |
| | | } |
| | | |
| | | function handleBatchDelete() { |
| | | if (multipleSelection.value.length === 0) return |
| | | ElMessageBox.confirm('å°å é¤éä¸çåçï¼æ¯å¦ç»§ç»ï¼', 'æç¤º', { |
| | | confirmButtonText: 'ç¡®å®', |
| | | cancelButtonText: 'åæ¶', |
| | | type: 'warning', |
| | | }).then(async () => { |
| | | const ids = multipleSelection.value.map((i) => i.id) |
| | | const { code } = await delBrand(ids) |
| | | if (code === 200) { |
| | | ElMessage.success('å 餿å') |
| | | getTableData() |
| | | } |
| | | }) |
| | | } |
| | | |
| | | onMounted(() => { |
| | | getTableData() |
| | | }) |
| | | |
| | | </script> |
| | | |
| | | <style scoped lang="scss"> |
| | | .table_list { margin-top: unset; } |
| | | .actions { |
| | | display: flex; |
| | | justify-content: space-between; |
| | | margin-bottom: 10px; |
| | | } |
| | | </style> |
| | | |
| | | |
| | |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="设å¤åç" prop="deviceBrand"> |
| | | <el-input v-model="form.deviceBrand" placeholder="请è¾å
¥è®¾å¤åç" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="ä¾åºå" prop="supplierName"> |
| | | <el-input v-model="form.supplierName" placeholder="请è¾å
¥ä¾åºå" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="åæ¾ä½ç½®" prop="storageLocation"> |
| | | <el-input v-model="form.storageLocation" placeholder="请è¾å
¥åæ¾ä½ç½®" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="åä½" prop="unit"> |
| | | <el-input v-model="form.unit" placeholder="请è¾å
¥åä½" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="å¯ç¨ææ§" prop="enableDepreciation"> |
| | | <el-switch v-model="form.enableDepreciation" :active-value="true" :inactive-value="false" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | |
| | | const { form, resetForm } = useFormData({ |
| | | deviceName: undefined, // 设å¤åç§° |
| | | deviceModel: undefined, // è§æ ¼åå· |
| | | deviceBrand: undefined, // 设å¤åç |
| | | supplierName: undefined, // ä¾åºå |
| | | storageLocation: undefined, // åæ¾ä½ç½® |
| | | enableDepreciation: false, // æ¯å¦å¯ç¨ææ§ |
| | | unit: undefined, // åä½ |
| | | number: undefined, // æ°é |
| | | taxIncludingPriceUnit: undefined, // å«ç¨åä»· |
| | |
| | | if (code == 200) { |
| | | form.deviceName = data.deviceName; |
| | | form.deviceModel = data.deviceModel; |
| | | form.deviceBrand = data.deviceBrand; |
| | | form.supplierName = data.supplierName; |
| | | form.storageLocation = data.storageLocation; |
| | | form.enableDepreciation = data.enableDepreciation; |
| | | form.unit = data.unit; |
| | | form.number = data.number; |
| | | form.taxIncludingPriceUnit = data.taxIncludingPriceUnit; |
| | |
| | | prop: "deviceModel", |
| | | }, |
| | | { |
| | | label: "设å¤åç", |
| | | align: "center", |
| | | prop: "deviceBrand", |
| | | }, |
| | | { |
| | | label: "ä¾åºå", |
| | | align: "center", |
| | | prop: "supplierName", |
| | |
| | | label: "åä½", |
| | | align: "center", |
| | | prop: "unit", |
| | | }, |
| | | { |
| | | label: "åæ¾ä½ç½®", |
| | | align: "center", |
| | | prop: "storageLocation", |
| | | }, |
| | | { |
| | | label: "æ°é", |
| | |
| | | prop: "unTaxIncludingPriceTotal", |
| | | }, |
| | | { |
| | | label: "å¯ç¨ææ§", |
| | | align: "center", |
| | | prop: "enableDepreciation", |
| | | formatData: (v) => (v ? "æ¯" : "å¦"), |
| | | }, |
| | | { |
| | | label: "å½å
¥äºº", |
| | | align: "center", |
| | | prop: "createUser", |