UserMenu.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div class="user-wrapper">
  3. <div class="content-box">
  4. <a href="https://www.stylefeng.cn" target="_blank">
  5. <span class="action">
  6. <a-icon type="question-circle-o"></a-icon>
  7. </span>
  8. </a>
  9. <notice-icon class="action"/>
  10. <a-dropdown>
  11. <span class="action ant-dropdown-link user-dropdown-menu">
  12. <a-avatar class="avatar" size="small" :src="avatar"/>
  13. <span>{{ nickname }}</span>
  14. </span>
  15. <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
  16. <a-menu-item key="4" v-if="mode === 'sidemenu'">
  17. <a @click="appToggled()" >
  18. <a-icon type="swap"/>
  19. <span>切换应用</span>
  20. </a>
  21. </a-menu-item>
  22. <a-menu-item key="5" v-if="hasPerm('sysUser:updatePwd')" >
  23. <a @click="updatePwd()" >
  24. <a-icon type="tool"/>
  25. <span>修改密码</span>
  26. </a>
  27. </a-menu-item>
  28. <a-menu-item key="0">
  29. <router-link :to="{ name: 'center' }">
  30. <a-icon type="user"/>
  31. <span>个人中心</span>
  32. </router-link>
  33. </a-menu-item>
  34. <a-menu-item key="1">
  35. <router-link :to="{ name: 'settings' }">
  36. <a-icon type="setting"/>
  37. <span>账户设置</span>
  38. </router-link>
  39. </a-menu-item>
  40. <a-menu-divider/>
  41. <a-menu-item key="3">
  42. <a href="javascript:;" @click="handleLogout">
  43. <a-icon type="logout"/>
  44. <span>退出登录</span>
  45. </a>
  46. </a-menu-item>
  47. </a-menu>
  48. </a-dropdown>
  49. </div>
  50. <a-modal
  51. title="切换应用"
  52. :visible="visible"
  53. :footer="null"
  54. :confirm-loading="confirmLoading"
  55. @cancel="handleCancel"
  56. >
  57. <a-form :form="form1" >
  58. <a-form-item
  59. :labelCol="labelCol"
  60. :wrapperCol="wrapperCol"
  61. label="选择应用"
  62. >
  63. <a-menu
  64. mode="inline"
  65. :default-selected-keys=this.defApp
  66. style="border-bottom:0px;lineHeight:62px;"
  67. >
  68. <a-menu-item v-for='(item) in userInfo.apps' :key="item.code" style="top:0px;" @click="switchApp(item.code)">
  69. {{item.name}}
  70. </a-menu-item>
  71. </a-menu>
  72. </a-form-item>
  73. </a-form>
  74. </a-modal>
  75. <a-modal
  76. title="修改密码"
  77. :visible="visible_updPwd"
  78. :confirm-loading="confirmLoading"
  79. @ok="handleOkUpdPwd"
  80. @cancel="handleCancel"
  81. >
  82. <a-form :form="form2">
  83. <a-form-item
  84. label="原密码"
  85. :labelCol="labelCol"
  86. :wrapperCol="wrapperCol"
  87. has-feedback
  88. >
  89. <a-input placeholder="请输入原密码" type="password" v-decorator="['password', {rules: [{required: true, message: '请输入原密码!'}]}]" />
  90. </a-form-item>
  91. <a-form-item
  92. label="新密码"
  93. :labelCol="labelCol"
  94. :wrapperCol="wrapperCol"
  95. has-feedback
  96. >
  97. <a-input placeholder="请输入新密码" type="password" v-decorator="['newPassword', {rules: [{required: true, message: '请输入新密码!'},{
  98. validator: validateToNextPassword,
  99. },]}]" />
  100. </a-form-item>
  101. <a-form-item
  102. label="重复新密码"
  103. :labelCol="labelCol"
  104. :wrapperCol="wrapperCol"
  105. has-feedback
  106. >
  107. <a-input placeholder="请再次输入新密码" type="password" v-decorator="['confirm', {rules: [{required: true, message: '请再次输入新密码!'},
  108. {
  109. validator: compareToFirstPassword,
  110. }]}]" />
  111. </a-form-item>
  112. </a-form>
  113. </a-modal>
  114. </div>
  115. </template>
  116. <script>
  117. import NoticeIcon from '@/components/NoticeIcon'
  118. import { mapActions, mapGetters } from 'vuex'
  119. import { ALL_APPS_MENU } from '@/store/mutation-types'
  120. import Vue from 'vue'
  121. import { message } from 'ant-design-vue/es'
  122. export default {
  123. name: 'UserMenu',
  124. components: {
  125. NoticeIcon,
  126. },
  127. props: {
  128. mode: {
  129. type: String,
  130. // sidemenu, topmenu
  131. default: 'sidemenu'
  132. },
  133. },
  134. data() {
  135. return {
  136. labelCol: {
  137. xs: { span: 24 },
  138. sm: { span: 5 }
  139. },
  140. wrapperCol: {
  141. xs: { span: 24 },
  142. sm: { span: 16 }
  143. },
  144. visible: false,
  145. visible_updPwd:false,
  146. confirmLoading: false,
  147. form1: this.$form.createForm(this),
  148. form2: this.$form.createForm(this),
  149. defApp:[]
  150. };
  151. },
  152. computed: {
  153. ...mapGetters(['nickname', 'avatar','userInfo'])
  154. },
  155. methods: {
  156. ...mapActions(['Logout','MenuChange','UpdatePwd']),
  157. handleLogout () {
  158. this.$confirm({
  159. title: '提示',
  160. content: '真的要注销登录吗 ?',
  161. onOk: () => {
  162. return this.Logout({}).then(() => {
  163. setTimeout(() => {
  164. window.location.reload()
  165. }, 16)
  166. }).catch(err => {
  167. this.$message.error({
  168. title: '错误',
  169. description: err.message
  170. })
  171. })
  172. },
  173. onCancel () {
  174. }
  175. })
  176. },
  177. /**
  178. * 打开切换应用框
  179. */
  180. appToggled () {
  181. this.visible = true;
  182. this.defApp.push(Vue.ls.get(ALL_APPS_MENU)[0].code)
  183. },
  184. /**
  185. * 打开修改密码框
  186. */
  187. updatePwd () {
  188. this.visible_updPwd = true;
  189. },
  190. compareToFirstPassword(rule, value, callback) {
  191. const form2 = this.form2;
  192. if (value && value !== form2.getFieldValue('newPassword')) {
  193. callback('请确认两次输入密码的一致性!');
  194. } else {
  195. callback();
  196. }
  197. },
  198. validateToNextPassword(rule, value, callback) {
  199. const form2 = this.form2;
  200. if (value && this.confirmDirty) {
  201. form2.validateFields(['confirm'], { force: true });
  202. }
  203. callback();
  204. },
  205. switchApp(appCode){
  206. this.visible = false;
  207. this.defApp=[]
  208. const applicationData = this.userInfo.apps.filter(item => item.code == appCode)
  209. const hideMessage = message.loading('正在切换应用!', 0)
  210. this.MenuChange(applicationData[0]).then((res)=>{
  211. hideMessage()
  212. }).catch((err)=>{
  213. message.error("应用切换异常");
  214. });
  215. },
  216. handleOkUpdPwd(){
  217. const { form2: { validateFields } } = this
  218. validateFields((errors, values) => {
  219. if(!errors){
  220. values.id = this.userInfo.id
  221. this.UpdatePwd(values).then((res) =>{
  222. if(res.success){
  223. this.$message.success('修改成功')
  224. this.handleCancel()
  225. }else{
  226. this.$message.error('修改失败:'+res.message)
  227. }
  228. })
  229. }
  230. })
  231. },
  232. handleCancel(){
  233. this.form1.resetFields();
  234. this.form2.resetFields();
  235. this.visible = false;
  236. this.visible_updPwd = false;
  237. }
  238. }
  239. }
  240. </script>
  241. <style lang="less" scoped>
  242. .appRedio {
  243. border:1px solid #91d5ff;
  244. padding:10px 20px;
  245. background: #e6f7ff;
  246. border-radius:2px;
  247. margin-bottom:10px;
  248. color: #91d5ff;
  249. /*display: inline;
  250. margin-bottom:10px;*/
  251. }
  252. </style>