|
| 1 | +<template> |
| 2 | + <div class="content"> |
| 3 | + <div id="tool-bar"> |
| 4 | + <el-card shadow="never"> |
| 5 | + <el-avatar shape="square" :size="400"><img src="./../../assets/icon/SOJ-thick-white-background.png" /></el-avatar> |
| 6 | + </el-card> |
| 7 | + <el-card class="item"> |
| 8 | + <div slot="header" class="clearfix"><i class="el-icon-setting" /> Tool Bar</div> |
| 9 | + <el-button v-if="isMine || this.$store.state.user.isStaff || this.$store.state.user.isRoot" type="primary" @click="submit()">Submit</el-button> |
| 10 | + <el-button @click="$router.go(-1);">Back</el-button> |
| 11 | + </el-card> |
| 12 | + </div> |
| 13 | + <div v-loading="!(isMine || this.$store.state.user.isStaff || this.$store.state.user.isRoot)" class="edit-content"> |
| 14 | + <el-card> |
| 15 | + <div slot="header" class="clearfix"><i class="el-icon-user" /> User Name</div> |
| 16 | + <el-input v-model="username"></el-input> |
| 17 | + </el-card> |
| 18 | + <el-card class="item"> |
| 19 | + <div slot="header" class="clearfix"><i class="el-icon-chat-line-square" /> Permissions</div> |
| 20 | + <el-checkbox v-model="isStaff" :disabled="!isStaffMe && !isRootMe">Staff</el-checkbox> |
| 21 | + <el-checkbox v-model="isRoot" :disabled="!isStaffMe && !isRootMe">Root</el-checkbox> |
| 22 | + <el-checkbox v-model="isActive" :disabled="(!isStaffMe && !isRootMe) || isMine">Active</el-checkbox> |
| 23 | + </el-card> |
| 24 | + <el-card class="item"> |
| 25 | + <div slot="header" class="clearfix"><i class="el-icon-chat-line-square" /> Introductions</div> |
| 26 | + <MarkdownEditor v-model="introduction" /> |
| 27 | + </el-card> |
| 28 | + </div> |
| 29 | + </div> |
| 30 | +</template> |
| 31 | + |
| 32 | +<script> |
| 33 | +import apiurl from './../../apiurl'; |
| 34 | +import MarkdownEditor from './../lib/MarkdownEditor.vue'; |
| 35 | +
|
| 36 | +export default { |
| 37 | + name: 'UserEdit', |
| 38 | + data() { |
| 39 | + return { |
| 40 | + username: 'Unknown', |
| 41 | + email: 'Unknown', |
| 42 | + introduction: 'loading...', |
| 43 | + isMine: false, |
| 44 | + isStaff: false, |
| 45 | + isRoot: false, |
| 46 | + isActive: true, |
| 47 | + isRootMe: false, |
| 48 | + isStaffMe: false, |
| 49 | + isActiveMe: true |
| 50 | + }; |
| 51 | + }, |
| 52 | + methods: { |
| 53 | + showEdit() { |
| 54 | + this.$axios |
| 55 | + .get(apiurl('/account/' + this.$route.params.id)) |
| 56 | + .then(res => { |
| 57 | + let data = res.data.res; |
| 58 | + this.isRootMe = this.$store.state.user.isRoot; |
| 59 | + this.isStaffMe = this.$store.state.user.isStaff; |
| 60 | + if (data.id == this.$store.state.user.userid) { |
| 61 | + this.isMine = true; |
| 62 | + } |
| 63 | + if (this.isMine || this.isRootMe || this.isStaffMe) { |
| 64 | + this.username = data.username; |
| 65 | + this.email = data.email; |
| 66 | + this.introduction = data.introduction; |
| 67 | + this.isStaff = data.is_staff; |
| 68 | + this.isRoot = data.is_superuser; |
| 69 | + this.isActive = data.is_active; |
| 70 | + } |
| 71 | + }); |
| 72 | + }, |
| 73 | + submit() { |
| 74 | + this.$axios |
| 75 | + .patch(apiurl('/account/' + this.$route.params.id), { |
| 76 | + username: this.username, |
| 77 | + introduction: this.introduction, |
| 78 | + is_staff: this.isStaff, |
| 79 | + is_superuser: this.isRoot, |
| 80 | + is_active: this.isActive |
| 81 | + }) |
| 82 | + .then(() => { |
| 83 | + this.$SegmentMessage.success(this, 'Submitted'); |
| 84 | + if (this.isMine) { |
| 85 | + this.$store.commit('userStaffChange', { |
| 86 | + isStaff: this.isStaff, |
| 87 | + isRoot: this.isRoot |
| 88 | + }); |
| 89 | + } |
| 90 | + }); |
| 91 | + } |
| 92 | + }, |
| 93 | + mounted() { |
| 94 | + this.showEdit(); |
| 95 | + }, |
| 96 | + components: { |
| 97 | + MarkdownEditor |
| 98 | + } |
| 99 | +}; |
| 100 | +</script> |
| 101 | + |
| 102 | +<style scoped> |
| 103 | +#tool-bar { |
| 104 | + margin-right: 30px; |
| 105 | +} |
| 106 | +
|
| 107 | +.edit-content { |
| 108 | + width: 100%; |
| 109 | +} |
| 110 | +
|
| 111 | +.content { |
| 112 | + display: flex; |
| 113 | +} |
| 114 | +
|
| 115 | +.item { |
| 116 | + margin-top: 20px; |
| 117 | +} |
| 118 | +</style> |
0 commit comments