|
|
@@ -1,80 +1,51 @@
|
|
|
<template>
|
|
|
<div class="edit-view">
|
|
|
- <page-title>
|
|
|
- <el-button @click="$router.go(-1)">取消</el-button>
|
|
|
- <el-button
|
|
|
- @click="del"
|
|
|
- :loading="$store.state.fetchingData"
|
|
|
- type="danger"
|
|
|
- v-if="formData.id && formData.id !== 1"
|
|
|
- >删除
|
|
|
- </el-button>
|
|
|
- <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
|
|
|
- </page-title>
|
|
|
- <div class="edit-view__content-wrapper">
|
|
|
- <div class="edit-view__content-section">
|
|
|
- <el-form
|
|
|
- :model="formData"
|
|
|
- :rules="rules"
|
|
|
- ref="form"
|
|
|
- label-width="80px"
|
|
|
- label-position="right"
|
|
|
- style="max-width: 500px;"
|
|
|
- >
|
|
|
- <el-form-item prop="avatar" label="头像">
|
|
|
- <crop-upload v-model="formData.avatar"></crop-upload>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="username" label="用户名">
|
|
|
- <el-input v-model="formData.username"></el-input>
|
|
|
- <div class="gen" @dblclick="gen"></div>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="nickname" label="昵称">
|
|
|
- <el-input v-model="formData.nickname"></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item v-if="formData.id" label="密码">
|
|
|
- <el-button type="primary" plain @click="resetPassword" size="mini">重置 </el-button>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item v-else prop="password" label="密码">
|
|
|
- <el-input v-model="formData.password"></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="phone" label="手机">
|
|
|
- <el-input v-model="formData.phone"></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="authorities" label="角色">
|
|
|
- <el-select
|
|
|
- v-model="formData.authorities"
|
|
|
- multiple
|
|
|
- placeholder="请选择"
|
|
|
- value-key="name"
|
|
|
- style="width:100%"
|
|
|
- >
|
|
|
- <el-option
|
|
|
- v-for="item in authorities"
|
|
|
- :key="item.name"
|
|
|
- :label="item.description"
|
|
|
- :value="item"
|
|
|
- >
|
|
|
- </el-option>
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item>
|
|
|
- <el-button @click="onSave" :loading="saving" type="primary">保存</el-button>
|
|
|
- <el-button @click="del" :disabled="saving" type="danger" v-if="formData.id && formData.id !== 1"
|
|
|
- >删除
|
|
|
- </el-button>
|
|
|
- <el-button @click="$router.go(-1)" :disabled="saving">取消</el-button>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ <el-form
|
|
|
+ :model="formData"
|
|
|
+ :rules="rules"
|
|
|
+ ref="form"
|
|
|
+ label-width="80px"
|
|
|
+ label-position="right"
|
|
|
+ style="max-width: 500px;"
|
|
|
+ >
|
|
|
+ <el-form-item prop="avatar" label="头像">
|
|
|
+ <crop-upload v-model="formData.avatar"></crop-upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="username" label="用户名">
|
|
|
+ <el-input v-model="formData.username"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="nickname" label="昵称">
|
|
|
+ <el-input v-model="formData.nickname"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item v-if="formData.id" label="密码">
|
|
|
+ <el-button type="primary" plain @click="resetPassword">重置 </el-button>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item v-else prop="password" label="密码">
|
|
|
+ <el-input v-model="formData.password"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="phone" label="手机">
|
|
|
+ <el-input v-model="formData.phone"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="email" label="邮箱">
|
|
|
+ <el-input v-model="formData.email"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="authorities" label="角色">
|
|
|
+ <el-select v-model="formData.authorities" multiple placeholder="请选择" value-key="name">
|
|
|
+ <el-option v-for="item in authorities" :key="item.name" :label="item.nameDesc" :value="item">
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button @click="onSave" :loading="saving" type="primary">保存</el-button>
|
|
|
+ <el-button @click="del" :loading="$store.state.fetchingData" type="danger" v-if="formData.id"
|
|
|
+ >删除
|
|
|
+ </el-button>
|
|
|
+ <el-button @click="$router.go(-1)">取消</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import { toSvg } from 'jdenticon';
|
|
|
-import { createIcon } from '@download/blockies';
|
|
|
-import faker from 'faker';
|
|
|
-faker.locale = 'zh_CN';
|
|
|
-console.log(faker);
|
|
|
export default {
|
|
|
created() {
|
|
|
if (this.$route.query.id) {
|
|
|
@@ -91,7 +62,7 @@ export default {
|
|
|
this.$http
|
|
|
.get('/authority/all')
|
|
|
.then(res => {
|
|
|
- this.authorities = res;
|
|
|
+ this.authorities = res.content;
|
|
|
})
|
|
|
.catch(e => {
|
|
|
console.log(e);
|
|
|
@@ -117,13 +88,16 @@ export default {
|
|
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
|
|
phone: [
|
|
|
{
|
|
|
- pattern: /^1[3-9]\d{9}$/,
|
|
|
+ regexp: /^1[3-9]\d{9}$/,
|
|
|
message: '请输入正确的手机号',
|
|
|
trigger: 'blur'
|
|
|
}
|
|
|
],
|
|
|
authorities: [{ required: true, message: '请选择角色', trigger: 'blur' }],
|
|
|
- saving: false
|
|
|
+ email: [
|
|
|
+ { required: true, message: '请输入邮箱', trigger: 'blur' },
|
|
|
+ { type: 'email', message: '请输入正确的邮箱', trigger: 'blur' }
|
|
|
+ ]
|
|
|
},
|
|
|
authorities: []
|
|
|
};
|
|
|
@@ -141,37 +115,39 @@ export default {
|
|
|
submit() {
|
|
|
this.saving = true;
|
|
|
this.$http
|
|
|
- .post(this.formData.id ? '/user/save' : '/user/create', this.formData, { body: 'json' })
|
|
|
+ .post('/user/save', this.formData, { body: 'json' })
|
|
|
.then(res => {
|
|
|
this.saving = false;
|
|
|
this.$message.success('成功');
|
|
|
this.formData = res;
|
|
|
- this.$router.replace({
|
|
|
- query: {
|
|
|
- id: res.id
|
|
|
- }
|
|
|
- });
|
|
|
+ this.$router.go(-1);
|
|
|
})
|
|
|
.catch(e => {
|
|
|
- console.log(e);
|
|
|
this.saving = false;
|
|
|
+ console.log(e);
|
|
|
this.$message.error(e.error);
|
|
|
});
|
|
|
},
|
|
|
del() {
|
|
|
this.$confirm('确认删除吗?', '提示', { type: 'warning' })
|
|
|
.then(() => {
|
|
|
- return this.$http.post(`/user/del/${this.formData.id}`);
|
|
|
- })
|
|
|
- .then(res => {
|
|
|
- this.$message.success('删除成功');
|
|
|
- this.$router.go(-1);
|
|
|
+ this.$http
|
|
|
+ .post({
|
|
|
+ url: '/userInfo/del',
|
|
|
+ data: {
|
|
|
+ id: this.formData.id
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ if (res.success) {
|
|
|
+ this.$message.success('成功');
|
|
|
+ this.$router.go(-1);
|
|
|
+ } else {
|
|
|
+ this.$message.warning('失败');
|
|
|
+ }
|
|
|
+ });
|
|
|
})
|
|
|
- .catch(e => {
|
|
|
- if ('cancel' !== e) {
|
|
|
- this.$message.error(e.error || '删除失败');
|
|
|
- }
|
|
|
- });
|
|
|
+ .catch(() => {});
|
|
|
},
|
|
|
resetPassword() {
|
|
|
this.$prompt('请输入新密码', '重置密码', { inputType: 'password' })
|
|
|
@@ -196,31 +172,8 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
.catch(() => {});
|
|
|
- },
|
|
|
- gen() {
|
|
|
- const icon = createIcon({
|
|
|
- size: 10,
|
|
|
- scale: 20
|
|
|
- });
|
|
|
- this.$http.post('/upload/base64', { base64: icon.toDataURL() }).then(res => {
|
|
|
- this.formData.avatar = res;
|
|
|
- });
|
|
|
- const card = faker.helpers.createCard();
|
|
|
- this.formData.username = card.username;
|
|
|
- this.formData.nickname = card.name;
|
|
|
- this.formData.phone = card.phone;
|
|
|
- this.$message('ok');
|
|
|
- console.log(card);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
|
-<style lang="less" scoped>
|
|
|
-.gen {
|
|
|
- position: absolute;
|
|
|
- top: 0;
|
|
|
- right: -50px;
|
|
|
- width: 50px;
|
|
|
- height: 32px;
|
|
|
-}
|
|
|
-</style>
|
|
|
+<style lang="less" scoped></style>
|