info.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <!--
  2. - Copyright (c) 2018-2025, lengleng All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions are met:
  6. -
  7. - Redistributions of source code must retain the above copyright notice,
  8. - this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. - notice, this list of conditions and the following disclaimer in the
  11. - documentation and/or other materials provided with the distribution.
  12. - Neither the name of the pig4cloud.com developer nor the names of its
  13. - contributors may be used to endorse or promote products derived from
  14. - this software without specific prior written permission.
  15. - Author: lengleng (wangiegie@gmail.com)
  16. -->
  17. <template>
  18. <div class="app-container calendar-list-container">
  19. <basic-container>
  20. <template>
  21. <el-tabs @tab-click="switchTab">
  22. <el-tab-pane label='信息管理' name='userManager'/>
  23. <el-tab-pane label='密码管理' name='passwordManager'/>
  24. </el-tabs>
  25. </template>
  26. <el-row>
  27. <el-col :span="12">
  28. <div class="grid-content bg-purple">
  29. <el-form :model="ruleForm2"
  30. :rules="rules2"
  31. ref="ruleForm2"
  32. label-width="100px"
  33. v-if="switchStatus==='userManager'"
  34. class="demo-ruleForm">
  35. <el-form-item label="用户名"
  36. prop="username">
  37. <el-input type="text"
  38. v-model="ruleForm2.username"
  39. disabled></el-input>
  40. </el-form-item>
  41. <el-form-item label="手机号" prop="phone">
  42. <el-input v-model="ruleForm2.phone" placeholder="验证码登录使用"></el-input>
  43. </el-form-item>
  44. <el-form-item label="头像">
  45. <el-upload
  46. class="avatar-uploader"
  47. action="/admin/file/upload"
  48. :headers="headers"
  49. :show-file-list="false"
  50. :on-success="handleAvatarSuccess">
  51. <img id="avatar" v-if="ruleForm2.avatar" :src="avatarUrl" class="avatar">
  52. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  53. </el-upload>
  54. </el-form-item>
  55. <el-form-item label="社交登录"
  56. prop="social">
  57. <a href="#"
  58. style="color: blue"
  59. @click="handleClick('wechat')">绑定微信</a>|
  60. <a href="#"
  61. style="color: blue"
  62. @click="handleClick('gitee')">绑定码云</a> |
  63. <a href="#"
  64. style="color: blue"
  65. @click="handleClick('osc')">开源中国</a>
  66. </el-form-item>
  67. <el-form-item>
  68. <el-button type="primary"
  69. @click="submitForm('ruleForm2')">提交
  70. </el-button>
  71. <el-button @click="resetForm('ruleForm2')">重置</el-button>
  72. </el-form-item>
  73. </el-form>
  74. <el-form :model="ruleForm2"
  75. :rules="rules2"
  76. ref="ruleForm2"
  77. label-width="100px"
  78. v-if="switchStatus==='passwordManager'"
  79. class="demo-ruleForm">
  80. <el-form-item label="原密码"
  81. prop="password">
  82. <el-input type="password"
  83. v-model="ruleForm2.password"
  84. auto-complete="off"></el-input>
  85. </el-form-item>
  86. <el-form-item label="密码"
  87. prop="newpassword1">
  88. <el-input type="password"
  89. v-model="ruleForm2.newpassword1"
  90. auto-complete="off"></el-input>
  91. </el-form-item>
  92. <el-form-item label="确认密码"
  93. prop="newpassword2">
  94. <el-input type="password"
  95. v-model="ruleForm2.newpassword2"
  96. auto-complete="off"></el-input>
  97. </el-form-item>
  98. <el-form-item>
  99. <el-button type="primary"
  100. @click="submitForm('ruleForm2')">提交
  101. </el-button>
  102. <el-button @click="resetForm('ruleForm2')">重置</el-button>
  103. </el-form-item>
  104. </el-form>
  105. </div>
  106. </el-col>
  107. </el-row>
  108. </basic-container>
  109. </div>
  110. </template>
  111. <script>
  112. import {handleDown} from "@/api/admin/user";
  113. import {handleImg, openWindow} from '@/util/util'
  114. import {mapState} from 'vuex'
  115. import store from "@/store";
  116. import request from '@/router/axios'
  117. export default {
  118. data() {
  119. var validatePass = (rule, value, callback) => {
  120. if (this.ruleForm2.password !== '') {
  121. if (value !== this.ruleForm2.newpassword1) {
  122. callback(new Error('两次输入密码不一致!'))
  123. } else {
  124. callback()
  125. }
  126. } else {
  127. callback()
  128. }
  129. }
  130. return {
  131. switchStatus: '',
  132. avatarUrl: '',
  133. show: false,
  134. headers: {
  135. Authorization: 'Bearer ' + store.getters.access_token
  136. },
  137. ruleForm2: {
  138. username: '',
  139. password: '',
  140. newpassword1: '',
  141. newpassword2: '',
  142. avatar: '',
  143. phone: ''
  144. },
  145. rules2: {
  146. password: [{required: true, min: 6, message: '原密码不能为空且不少于6位', trigger: 'change'}],
  147. newpassword1: [{required: false, min: 6, message: '不少于6位', trigger: 'change'}],
  148. newpassword2: [{required: false, validator: validatePass, trigger: 'blur'}]
  149. }
  150. }
  151. },
  152. created() {
  153. this.ruleForm2.username = this.userInfo.username
  154. this.ruleForm2.phone = this.userInfo.phone
  155. this.ruleForm2.avatar = this.userInfo.avatar
  156. this.switchStatus = 'userManager'
  157. handleImg(this.userInfo.avatar, 'avatar')
  158. },
  159. computed: {
  160. ...mapState({
  161. userInfo: state => state.user.userInfo
  162. }),
  163. },
  164. methods: {
  165. switchTab(tab, event) {
  166. if (tab.name === 'userManager') {
  167. handleImg(this.ruleForm2.avatar, 'avatar')
  168. }
  169. this.switchStatus = tab.name
  170. },
  171. submitForm(formName) {
  172. this.$refs[formName].validate(valid => {
  173. if (valid) {
  174. request({
  175. url: '/admin/user/edit',
  176. method: 'put',
  177. data: this.ruleForm2
  178. }).then(response => {
  179. if (response.data.data) {
  180. this.$notify({
  181. title: '成功',
  182. message: '修改成功',
  183. type: 'success',
  184. duration: 2000
  185. })
  186. // 修改密码之后强制重新登录
  187. if (this.switchStatus === 'passwordManager') {
  188. this.$store.dispatch('LogOut').then(() => {
  189. location.reload() // 为了重新实例化vue-router对象 避免bug
  190. })
  191. }
  192. } else {
  193. this.$notify({
  194. title: '失败',
  195. message: response.data.msg,
  196. type: 'error',
  197. duration: 2000
  198. })
  199. }
  200. }).catch(() => {
  201. this.$notify({
  202. title: '失败',
  203. message: '修改失败',
  204. type: 'error',
  205. duration: 2000
  206. })
  207. })
  208. } else {
  209. return false
  210. }
  211. })
  212. },
  213. resetForm(formName) {
  214. this.$refs[formName].resetFields()
  215. },
  216. handleClick(thirdpart) {
  217. let appid, client_id, redirect_uri, url
  218. redirect_uri = encodeURIComponent(window.location.origin + '/#/authredirect')
  219. if (thirdpart === 'wechat') {
  220. appid = 'wxd1678d3f83b1d83a'
  221. url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&state=WX-BIND&response_type=code&scope=snsapi_login#wechat_redirect'
  222. } else if (thirdpart === 'tencent') {
  223. client_id = '101322838'
  224. url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&state=QQ-BIND&client_id=' + client_id + '&redirect_uri=' + redirect_uri
  225. } else if (thirdpart === 'gitee') {
  226. client_id = '8fc54e0e76e7842cf767c3ae3b9fdc48c03cefed27aa565ff7b2a39d142d9892'
  227. url = 'https://gitee.com/oauth/authorize?response_type=code&state=GITEE--BIND&client_id=' + client_id + '&redirect_uri=' +redirect_uri
  228. } else if (thirdpart === 'osc') {
  229. client_id = 'neIIqlwGsjsfsA6uxNqD'
  230. url = 'https://www.oschina.net/action/oauth2/authorize?response_type=code&client_id=' + client_id + '&state=OSC-BIND&redirect_uri=' + redirect_uri
  231. }
  232. openWindow(url, thirdpart, 540, 540)
  233. },
  234. handleAvatarSuccess(res, file) {
  235. this.avatarUrl = URL.createObjectURL(file.raw);
  236. this.ruleForm2.avatar = res.data.bucketName + "-" + res.data.fileName;
  237. }
  238. }
  239. }
  240. </script>
  241. <style>
  242. .avatar-uploader .el-upload {
  243. border: 1px dashed #d9d9d9;
  244. border-radius: 6px;
  245. cursor: pointer;
  246. position: relative;
  247. overflow: hidden;
  248. }
  249. .avatar-uploader .el-upload:hover {
  250. border-color: #409EFF;
  251. }
  252. .avatar-uploader-icon {
  253. font-size: 28px !important;
  254. color: #8c939d !important;
  255. width: 178px !important;
  256. height: 178px !important;
  257. line-height: 178px !important;
  258. text-align: center !important;
  259. }
  260. .avatar {
  261. width: 178px;
  262. height: 178px;
  263. display: block;
  264. }
  265. </style>