人员管理增加修改

This commit is contained in:
2026-06-02 09:15:38 +08:00
parent 92165c914a
commit 05a72ac7dd
6 changed files with 212 additions and 87 deletions
+124 -8
View File
@@ -16,8 +16,8 @@
<th>工号</th>
<th>卡号</th>
<th>卡号2</th>
<th>操作</th>
</tr>
</thead>
<tbody class="ant-table-tbody">
<tr v-for="(item, index) in list" :key="index">
@@ -27,6 +27,12 @@
<td>{{ item.number }}</td>
<td>{{ item.ic }}</td>
<td>{{ item.ic2 }}</td>
<td>
<view class="action-btns">
<view class="ant-btn edit-btn" @click="edit(item)">编辑</view>
<!-- <view class="ant-btn delete-btn" @click="remove(item)">删除</view> -->
</view>
</td>
</tr>
</tbody>
</table>
@@ -102,7 +108,7 @@
<uni-row>
<uni-col>
<view class="form-btn">
<view class="ant-btn" @click="submit">保存</view>
<view class="ant-btn" @click="submit">{{ isEdit ? '更新' : '保存' }}</view>
<view class="ant-btn" style="margin-left: 20px;" @click="close">取消</view>
</view>
</uni-col>
@@ -134,6 +140,8 @@ export default {
],
page: 1,
totalPage: 0,
isEdit: false,
editId: null,
form: {
name: '',
ic: '',
@@ -149,6 +157,8 @@ export default {
methods: {
add() {
this.isEdit = false
this.editId = null
this.$refs.popup.open()
this.form = {
name: '',
@@ -167,8 +177,53 @@ export default {
},
close() {
this.$refs.popup.close()
this.isEdit = false
this.editId = null
uni.$off('ic')
},
edit(item) {
this.isEdit = true
this.editId = item.id
this.form = {
name: item.name,
ic: item.ic,
ic2: item.ic2 || '',
number: item.number || '',
type: item.type || ''
}
this.$refs.popup.open()
uni.$on('ic', (val) => {
if (!this.form.ic) {
this.form.ic = val
} else if (!this.form.ic2) {
this.form.ic2 = val
}
})
},
async remove(item) {
uni.showModal({
title: '确认删除',
content: `确定要删除 ${item.name} 吗?`,
success: async (res) => {
if (res.confirm) {
try {
await db.deleteInformationType('user', { id: item.id })
uni.showToast({
title: '删除成功',
icon: 'none'
})
this.getList()
} catch (error) {
console.log(error)
uni.showToast({
title: '删除失败',
icon: 'none'
})
}
}
}
})
},
async submit() {
if (this.form.name == '' || this.form.ic == '') {
return false
@@ -179,17 +234,33 @@ export default {
await db.addUserTable()
}
try {
await db.addTabItem(tableName, { ...this.form })
if (this.isEdit) {
// 编辑模式
await db.updateSQL(tableName, {
name: this.form.name,
ic: this.form.ic,
ic2: this.form.ic2,
number: this.form.number,
type: this.form.type
}, 'id', this.editId)
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
// 新增模式
await db.addTabItem(tableName, { ...this.form })
uni.showToast({
title: '保存成功',
icon: 'none'
})
}
this.$refs.popup.close()
uni.showToast({
title: '保存成功',
icon: 'none'
})
this.getList()
} catch (error) {
console.log(error)
uni.showToast({
title: '保存失败',
title: this.isEdit ? '更新失败' : '保存失败',
icon: 'none'
})
}
@@ -295,4 +366,49 @@ export default {
.form-btn{
margin-top: 30px;
}
.action-btns{
display: flex;
gap: 10px;
justify-content: center;
}
.edit-btn{
/* background: #1890ff;
border-color: #1890ff; */
width: 60px;
height: 36px;
line-height: 32px;
font-size: 14px;
}
.delete-btn{
/* background: #ff4d4f;
border-color: #ff4d4f; */
width: 60px;
height: 36px;
line-height: 32px;
font-size: 14px;
}
.edit-btn:hover{
/* background: #40a9ff;
border-color: #40a9ff; */
}
.delete-btn:hover{
/* background: #ff7875;
border-color: #ff7875; */
}
/* 表格内容自动换行 */
.ant-table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.ant-table th,
.ant-table td {
padding: 10px 8px;
text-align: center;
word-wrap: break-word;
word-break: break-all;
overflow-wrap: break-word;
max-width: 0;
}
</style>