Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

fix: edit user #68

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/models/oneid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class User {
password: this.password,
require_reset_password: this.requireResetPassword,
has_password: this.hasPassword,
is_extern_user: this.isExternUser,
}
if (!data.posix_user) {
delete data.posix_user
Expand Down
5 changes: 5 additions & 0 deletions src/oneid-app/admin/group/user/EditUser.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
.ui-edit-user {
.ui-form-drawer();

.title {
display: flex;
justify-content: space-between;
}

.international-mobile {
.ivu-select-selection {
width: 88px;
Expand Down
50 changes: 46 additions & 4 deletions src/oneid-app/admin/group/user/EditUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ interface InternationalMobile {
:transfer="true"
className="ui-edit-user"
>
<div class="title">{{ isNew ? "添加账号" : "编辑账号" }}</div>
<div class="title">
<span>{{ isNew ? "添加账号" : "编辑账号" }}</span>
<Button @click="doConvertExternOrIntra()">切换为{{ isExternUser ? "内部" : "外部" }}账号</Button>
</div>
<Form
v-if="showDrawer && rules"
:model="form"
Expand Down Expand Up @@ -78,6 +81,9 @@ interface InternationalMobile {
:placeholder="'请添加' + item.name"
></Input>
</FormItem>
<FormItem v-if="customUser" prop="customUser" label="Custom">
<pre>{{customUser}}</pre>
</FormItem>
</Form>
<div class="drawer-footer flex-row flex-auto">
<Button type="default" @click="doCancel">取消</Button>
Expand Down Expand Up @@ -160,6 +166,19 @@ export default class EditUser extends Vue {
return !this.form!.id
}

get isExternUser() {
return this.form!.isExternUser
}

get customUser() {
const data = this.form!.custom_user ? JSON.stringify(this.form!.custom_user, null, 2) : ''
if(!data) {
return ''
}

return data
}

initForm() {
const {user, node} = this
if (user) {
Expand All @@ -184,6 +203,14 @@ export default class EditUser extends Vue {
const result = await config.Config.getInternationalMobile()
this.internationalMobileList = result
this.areaCode = result[0].state_code

result.forEach(item => {
if(this.form!.mobile.indexOf(item.state_code) > 0) {
this.areaCode = item.state_code
}
})

this.form!.mobile = this.form!.mobile.replace(`+${this.areaCode} `, '')
}

showResetPassword() {
Expand Down Expand Up @@ -239,16 +266,17 @@ export default class EditUser extends Vue {
return
}

const user = cloneDeep(this.form!)
if(this.form!.mobile) {
this.form!.mobile = `+${this.areaCode} ${this.form!.mobile}`
user!.mobile = `+${this.areaCode} ${this.form!.mobile}`
}

this.$Loading.start()
try {
if (this.isNew) {
await api.User.create(this.form!)
await api.User.create(user)
} else {
await api.User.partialUpdate(this.form!)
await api.User.partialUpdate(user)
}
this.$Loading.finish()
this.$Message.success('保存成功')
Expand Down Expand Up @@ -279,6 +307,20 @@ export default class EditUser extends Vue {
this.$emit('on-save')
}

async doConvertExternOrIntra() {
this.form!.isExternUser = !this.form!.isExternUser
try {
if(this.form!.isExternUser) {
await api.User.convertExtern(this.form!)
} else {
await api.User.convertIntra(this.form!)
}
this.$Message.success('切换成功')
} catch(e) {
this.$Message.success('切换失败')
}
}

async doSaveAndContinue() {
this.doSave(true)
}
Expand Down
12 changes: 12 additions & 0 deletions src/services/oneid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ export class User {
const resp = await http.get(url)
return resp.data
}
static async convertIntra(user) {
const url = `/siteapi/oneid/user/${user.username}/convert/intra/`
const data = user.toData()
const resp = await http.patch(url, data)
return resp.data
}
static async convertExtern(user) {
const url = `/siteapi/oneid/user/${user.username}/convert/extern/`
const data = user.toData()
const resp = await http.patch(url, data)
return resp.data
}
}

export class App {
Expand Down