Browse Source

用户

master
maochaoying 2 years ago
parent
commit
866b57fb42
  1. 75
      src/components/User.vue

75
src/components/User.vue

@ -10,7 +10,7 @@
</t-space> </t-space>
</template> </template>
<template #actions> <template #actions>
<t-button theme="primary" @click="visible = true"> 新增用户 </t-button>
<t-button theme="primary" @click="addUser"> 新增用户 </t-button>
</template> </template>
<t-drawer <t-drawer
size="medium" size="medium"
@ -20,7 +20,7 @@
:visible="visible" :visible="visible"
@close="handleClose" @close="handleClose"
:onConfirm="handleClose" :onConfirm="handleClose"
header="新增用户"
:header="operType == 1 ? '新增用户' : '修改用户'"
> >
<t-form <t-form
:data="formData" :data="formData"
@ -33,6 +33,7 @@
<t-input <t-input
v-model="formData.username" v-model="formData.username"
placeholder="请输入用户名" placeholder="请输入用户名"
:disabled="operType == 2"
></t-input> ></t-input>
</t-form-item> </t-form-item>
<t-form-item name="password"> <t-form-item name="password">
@ -55,7 +56,11 @@
<t-form-item> <t-form-item>
<t-space size="10px"> <t-space size="10px">
<t-button theme="primary" type="submit">提交</t-button> <t-button theme="primary" type="submit">提交</t-button>
<t-button theme="default" variant="base" type="reset"
<t-button
v-if="operType == 1"
theme="default"
variant="base"
type="reset"
>重置</t-button >重置</t-button
> >
</t-space> </t-space>
@ -87,6 +92,7 @@ const INITIAL_DATA = {
export default { export default {
data() { data() {
return { return {
operType: 1,
formData: { ...INITIAL_DATA }, formData: { ...INITIAL_DATA },
rules: { rules: {
username: [ username: [
@ -147,13 +153,23 @@ export default {
cell: (h, { row }) => { cell: (h, { row }) => {
if (row.username != 'admin') { if (row.username != 'admin') {
return ( return (
<div>
<t-button
theme="danger"
onClick={() => this.delUser(row.username)}
>
删除
</t-button>
<div style={{ display: 'flex' }}>
<div>
<t-button
theme="danger"
onClick={() => this.delUser(row.username)}
>
删除
</t-button>
</div>
<div style={{ marginLeft: '16px' }}>
<t-button
theme="primary"
onClick={() => this.updateUser(row)}
>
修改
</t-button>
</div>
</div> </div>
) )
} }
@ -162,8 +178,26 @@ export default {
], ],
} }
}, },
methods: { methods: {
addUser() {
this.operType = 1
this.formData = {
username: '',
role: '',
password: '',
}
this.visible = true
},
updateUser(row) {
console.log(row)
this.formData = {
username: row.username,
role: row.role,
password: '',
}
this.operType = 2
this.visible = true
},
handleClose() { handleClose() {
this.formData = { ...INITIAL_DATA } this.formData = { ...INITIAL_DATA }
this.visible = false this.visible = false
@ -197,14 +231,19 @@ export default {
async onSubmit({ validateResult, firstError }) { async onSubmit({ validateResult, firstError }) {
if (validateResult === true) { if (validateResult === true) {
// //
const res = await addUserApi(this.formData)
if (res?.code == 200) {
this.formData = { ...INITIAL_DATA }
this.visible = false
this.$message.success('提交成功')
this.getUserList()
if (this.operType == 1) {
const res = await addUserApi(this.formData)
if (res?.code == 200) {
this.formData = { ...INITIAL_DATA }
this.visible = false
this.$message.success('提交成功')
this.getUserList()
} else {
this.$message.error(res.msg)
}
} else { } else {
this.$message.error(res.msg)
//
console.log(123)
} }
} else { } else {
this.$message.warning(firstError) this.$message.warning(firstError)

Loading…
Cancel
Save