user.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <!--简洁用户菜单-->
  3. <div class="right lite infos">
  4. <i class="infoNumberTow" v-if="items.length > 0"></i>
  5. <el-dropdown v-if="userScope" class="user-box" placement="top" @command="handleCommandValue">
  6. <el-button type="text" class="name">{{ value || '请选择当前域' }}<i class="el-icon-arrow-down el-icon--right"></i></el-button>
  7. <el-dropdown-menu slot="dropdown">
  8. <el-dropdown-item :command="item.code" v-for="item in options" :key="item.code">{{ item.name }}</el-dropdown-item>
  9. </el-dropdown-menu>
  10. </el-dropdown>
  11. <span style="margin: 5px;"></span>
  12. <el-dropdown class="user-box" placement="top" @command="handleCommand" :hide-on-click="false" @visible-change="change">
  13. <el-button type="text" class="name">{{ (userinfo && userinfo.name) || '管理員' }}</el-button>
  14. <span style="margin: 5px;">|</span>
  15. <el-dropdown-menu slot="dropdown">
  16. <el-dropdown-item command="passwd"><i class="el-icon-edit"></i> 修改密码</el-dropdown-item>
  17. <!-- <el-dropdown-item><i class="el-icon-chat-dot-round"></i>系统消息</el-dropdown-item> -->
  18. </el-dropdown-menu>
  19. </el-dropdown>
  20. <el-button type="text" @click="handleLogout">退出</el-button>
  21. <data-dlg
  22. ref="passwd"
  23. title="修改密码"
  24. width="400px"
  25. :visible.sync="passDlg"
  26. :data="passForm"
  27. :options="{ 'label-width': '80px', size: 'mini' }"
  28. :meta="passFields"
  29. @save="handleSavePass"
  30. @cancel="passDlg = false"
  31. >
  32. </data-dlg>
  33. </div>
  34. </template>
  35. <script>
  36. import { mapActions, mapGetters, createNamespacedHelpers } from 'vuex';
  37. import DataDlg from '@naf/data/form-dlg.vue';
  38. const { mapState, mapActions: userMapActions } = createNamespacedHelpers('naf/user');
  39. const userScope = eval(process.env.VUE_APP_USER_SCOPE);
  40. export default {
  41. components: {
  42. DataDlg,
  43. },
  44. data() {
  45. const checkPass = ref => {
  46. return (rule, value, callback) => {
  47. if (value === '') {
  48. callback(new Error('请输入新密码'));
  49. } else {
  50. if (this.$refs[ref].form.confirm !== '') {
  51. this.$refs[ref].$refs['form'].validateField('confirm');
  52. }
  53. callback();
  54. }
  55. };
  56. };
  57. const checkConfirm = ref => {
  58. return (rule, value, callback) => {
  59. if (value === '') {
  60. callback(new Error('请再次输入新密码'));
  61. } else if (value !== this.$refs[ref].form.newpass) {
  62. callback(new Error('两次输入密码不一致!'));
  63. } else {
  64. callback();
  65. }
  66. };
  67. };
  68. return {
  69. userScope,
  70. options: [],
  71. value: '',
  72. task: false,
  73. taskDlg: false,
  74. passDlg: false,
  75. passForm: {},
  76. passFields: [
  77. { name: 'oldpass', label: '原密码', required: true, formOpts: { inputType: 'password' }, rules: [{ required: true, message: '请输入原密码' }] },
  78. {
  79. name: 'newpass',
  80. label: '新密码',
  81. required: true,
  82. formOpts: { inputType: 'password' },
  83. rules: [
  84. { required: true, message: '请输入新密码' },
  85. { validator: checkPass('passwd'), trigger: 'blur' },
  86. ],
  87. },
  88. {
  89. name: 'confirm',
  90. label: '密码确认',
  91. required: true,
  92. formOpts: { inputType: 'password' },
  93. rules: [
  94. { required: true, message: '请重新输入新密码' },
  95. { validator: checkConfirm('passwd'), trigger: 'blur' },
  96. ],
  97. },
  98. ],
  99. };
  100. },
  101. props: {
  102. menuCollapse: Boolean,
  103. },
  104. async mounted() {
  105. const res = await this.domains();
  106. if (res) {
  107. this.options = res.data;
  108. if (this.options.length > 0) {
  109. const domain = sessionStorage.getItem('x-domain');
  110. if (domain) {
  111. this.handleCommandValue(domain);
  112. } else {
  113. this.handleCommandValue(this.options[0].code);
  114. }
  115. }
  116. }
  117. },
  118. methods: {
  119. ...mapActions({
  120. logout: 'login/logout',
  121. passwd: 'login/passwd',
  122. }),
  123. ...userMapActions(['taskList', 'domains']),
  124. async handleLogout() {
  125. const res = await this.logout();
  126. },
  127. handleCommand(command) {
  128. if (command === 'logout') {
  129. this.handleLogout();
  130. } else if (command == 'infos') {
  131. this.taskDlg = true;
  132. } else if (command == 'passwd') {
  133. this.passDlg = true;
  134. }
  135. },
  136. change(e) {
  137. if (e == false) {
  138. this.taskDlg = false;
  139. this.task = false;
  140. }
  141. },
  142. async handleSavePass(payload) {
  143. const res = await this.passwd(payload.data);
  144. if (this.$checkRes(res, '修改用户密码成功')) {
  145. this.passDlg = false;
  146. }
  147. },
  148. taskBtn() {
  149. this.task = true;
  150. },
  151. handleCommandValue(command) {
  152. const val = this.options.filter(p => command === p.code);
  153. this.value = val[0].name;
  154. window.sessionStorage.setItem('x-domain', command);
  155. },
  156. },
  157. computed: {
  158. ...mapGetters(['userinfo']),
  159. ...mapState(['items']),
  160. },
  161. };
  162. </script>
  163. <style lang="less" scoped>
  164. .right.lite {
  165. font-size: 14px;
  166. }
  167. .el-button--text {
  168. color: white;
  169. }
  170. .name {
  171. color: #fff;
  172. }
  173. .el-button--text {
  174. color: white;
  175. }
  176. .user-box {
  177. display: inline;
  178. }
  179. .infos {
  180. position: relative;
  181. }
  182. .infoNumberTow {
  183. position: absolute;
  184. background: #a30202;
  185. color: #fff;
  186. border-radius: 20px;
  187. padding: 5%;
  188. line-height: 1.5em;
  189. font-size: 0.7em;
  190. left: -10%;
  191. top: 10%;
  192. z-index: 999;
  193. }
  194. .infoNumber {
  195. position: absolute;
  196. background: #a30202;
  197. color: #fff;
  198. border-radius: 20px;
  199. padding: 0 3%;
  200. line-height: 1.5em;
  201. font-size: 0.7em;
  202. left: 2%;
  203. top: 0;
  204. z-index: 999;
  205. }
  206. .userList {
  207. width: 480px;
  208. position: absolute;
  209. left: -490px;
  210. top: 0%;
  211. }
  212. </style>