|
|
@@ -0,0 +1,109 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <el-form :model="formData" :rules="rules" ref="form" label-width="80px"
|
|
|
+ label-position="right" size="small">
|
|
|
+ <el-form-item prop="avatar" label="头像">
|
|
|
+ <single-upload v-model="formData.avatar"></single-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 prop="phone" label="手机">
|
|
|
+ <el-input v-model="formData.phone"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="coin" label="余额">
|
|
|
+ <el-input-number v-model="formData.coin"></el-input-number>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="authorities" label="角色">
|
|
|
+ <el-select v-model="formData.authorities" value-key='id'
|
|
|
+ multiple>
|
|
|
+ <el-option v-for="item in authorities" :label="item.name"
|
|
|
+ :value="item" :key="item.id"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" @click="save" :loading="loading">保存
|
|
|
+ </el-button>
|
|
|
+ <el-button type="danger" @click="del" :loading="loading" plain>
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ created() {
|
|
|
+ if (this.$route.params.formData) {
|
|
|
+ this.formData = this.$route.params.formData;
|
|
|
+ } else {
|
|
|
+ this.$http.get(`/user/get/${this.$route.query.id}`).then(res => {
|
|
|
+ if (res.success) {
|
|
|
+ this.formData = res.data;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.$http.get('/authority/all').then(res => {
|
|
|
+ if (res.success) {
|
|
|
+ this.authorities = res.data;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ rules: {},
|
|
|
+ formData: {
|
|
|
+ authorities: [],
|
|
|
+ },
|
|
|
+ loading: false,
|
|
|
+ authorities: [],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ save() {
|
|
|
+ this.loading = true;
|
|
|
+ this.$axios
|
|
|
+ .post('/user/save', this.formData)
|
|
|
+ .then(res => {
|
|
|
+ this.loading = false;
|
|
|
+ if (res.data.success) {
|
|
|
+ this.$message.success('保存成功');
|
|
|
+ } else {
|
|
|
+ this.$message.error(res.data.error);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ this.loading = false;
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ del() {
|
|
|
+ this.$confirm('此操作不可恢复, 是否继续删除?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ this.loading = true;
|
|
|
+ return this.$axios.delete(`/user/${this.formData.id}`);
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ this.loading = false;
|
|
|
+ this.$message.success('删除成功');
|
|
|
+ this.$router.go(-1);
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ this.loading = false;
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+</style>>
|