info.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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
  30. v-if="switchStatus==='userManager'"
  31. ref="ruleForm2"
  32. :model="ruleForm2"
  33. :rules="rules2"
  34. label-width="100px"
  35. class="demo-ruleForm">
  36. <el-form-item
  37. label="用户名"
  38. prop="username">
  39. <el-input
  40. v-model="ruleForm2.username"
  41. type="text"
  42. disabled/>
  43. </el-form-item>
  44. <el-form-item label="手机号" prop="phone">
  45. <el-input v-model="ruleForm2.phone" placeholder="验证码登录使用"/>
  46. </el-form-item>
  47. <el-form-item label="头像">
  48. <el-upload
  49. :headers="headers"
  50. :show-file-list="false"
  51. :on-success="handleAvatarSuccess"
  52. class="avatar-uploader"
  53. action="/admin/sys-file/upload">
  54. <img v-if="ruleForm2.avatar" id="avatar" :src="avatarUrl" class="avatar">
  55. <i v-else class="el-icon-plus avatar-uploader-icon"/>
  56. </el-upload>
  57. </el-form-item>
  58. <el-form-item
  59. label="社交登录"
  60. prop="social">
  61. <a
  62. href="#"
  63. style="color: blue"
  64. @click="handleClick('wechat')">绑定微信</a>|
  65. <a
  66. href="#"
  67. style="color: blue"
  68. @click="handleClick('gitee')">绑定码云</a> |
  69. <a
  70. href="#"
  71. style="color: blue"
  72. @click="handleClick('osc')">开源中国</a>
  73. </el-form-item>
  74. <el-form-item>
  75. <el-button
  76. type="primary"
  77. @click="submitForm('ruleForm2')">提交
  78. </el-button>
  79. <el-button @click="resetForm('ruleForm2')">重置</el-button>
  80. </el-form-item>
  81. </el-form>
  82. <el-form
  83. v-if="switchStatus==='passwordManager'"
  84. ref="ruleForm2"
  85. :model="ruleForm2"
  86. :rules="rules2"
  87. label-width="100px"
  88. class="demo-ruleForm">
  89. <el-form-item
  90. label="原密码"
  91. prop="password">
  92. <el-input
  93. v-model="ruleForm2.password"
  94. type="password"
  95. auto-complete="off"/>
  96. </el-form-item>
  97. <el-form-item
  98. label="密码"
  99. prop="newpassword1">
  100. <el-input
  101. v-model="ruleForm2.newpassword1"
  102. type="password"
  103. auto-complete="off"/>
  104. </el-form-item>
  105. <el-form-item
  106. label="确认密码"
  107. prop="newpassword2">
  108. <el-input
  109. v-model="ruleForm2.newpassword2"
  110. type="password"
  111. auto-complete="off"/>
  112. </el-form-item>
  113. <el-form-item>
  114. <el-button
  115. type="primary"
  116. @click="submitForm('ruleForm2')">提交
  117. </el-button>
  118. <el-button @click="resetForm('ruleForm2')">重置</el-button>
  119. </el-form-item>
  120. </el-form>
  121. </div>
  122. </el-col>
  123. </el-row>
  124. </basic-container>
  125. </div>
  126. </template>
  127. <script>
  128. import { handleImg, openWindow } from '@/util/util'
  129. import { mapState } from 'vuex'
  130. import store from '@/store'
  131. import { getStore } from '@/util/store'
  132. import request from '@/router/axios'
  133. export default {
  134. data() {
  135. var validatePass = (rule, value, callback) => {
  136. if (this.ruleForm2.password !== '') {
  137. if (value !== this.ruleForm2.newpassword1) {
  138. callback(new Error('两次输入密码不一致!'))
  139. } else {
  140. callback()
  141. }
  142. } else {
  143. callback()
  144. }
  145. }
  146. return {
  147. switchStatus: '',
  148. avatarUrl: '',
  149. show: false,
  150. headers: {
  151. 'Authorization': 'Bearer ' + store.getters.access_token,
  152. 'TENANT-ID': getStore({ name: 'tenantId' })
  153. },
  154. ruleForm2: {
  155. username: '',
  156. password: '',
  157. newpassword1: '',
  158. newpassword2: '',
  159. avatar: '',
  160. phone: ''
  161. },
  162. rules2: {
  163. password: [{ required: true, min: 6, message: '原密码不能为空且不少于6位', trigger: 'change' }],
  164. newpassword1: [{ required: false, min: 6, message: '不少于6位', trigger: 'change' }],
  165. newpassword2: [{ required: false, validator: validatePass, trigger: 'blur' }]
  166. }
  167. }
  168. },
  169. created() {
  170. this.ruleForm2.username = this.userInfo.username
  171. this.ruleForm2.phone = this.userInfo.phone
  172. this.ruleForm2.avatar = this.userInfo.avatar
  173. this.switchStatus = 'userManager'
  174. handleImg(this.userInfo.avatar, 'avatar')
  175. },
  176. computed: {
  177. ...mapState({
  178. userInfo: state => state.user.userInfo
  179. })
  180. },
  181. methods: {
  182. switchTab(tab) {
  183. if (tab.name === 'userManager') {
  184. handleImg(this.ruleForm2.avatar, 'avatar')
  185. }
  186. this.switchStatus = tab.name
  187. },
  188. submitForm(formName) {
  189. this.$refs[formName].validate(valid => {
  190. if (valid) {
  191. request({
  192. url: '/admin/user/edit',
  193. method: 'put',
  194. data: this.ruleForm2
  195. }).then(response => {
  196. if (response.data.data) {
  197. this.$notify({
  198. title: '成功',
  199. message: '修改成功',
  200. type: 'success',
  201. duration: 2000
  202. })
  203. // 修改密码之后强制重新登录
  204. if (this.switchStatus === 'passwordManager') {
  205. this.$store.dispatch('LogOut').then(() => {
  206. location.reload() // 为了重新实例化vue-router对象 避免bug
  207. })
  208. }
  209. } else {
  210. this.$notify({
  211. title: '失败',
  212. message: response.data.msg,
  213. type: 'error',
  214. duration: 2000
  215. })
  216. }
  217. }).catch(() => {
  218. this.$notify({
  219. title: '失败',
  220. message: '修改失败',
  221. type: 'error',
  222. duration: 2000
  223. })
  224. })
  225. } else {
  226. return false
  227. }
  228. })
  229. },
  230. resetForm(formName) {
  231. this.$refs[formName].resetFields()
  232. },
  233. handleClick(thirdpart) {
  234. let appid, client_id, redirect_uri, url
  235. redirect_uri = encodeURIComponent(window.location.origin + '/#/authredirect')
  236. if (thirdpart === 'wechat') {
  237. appid = 'wxd1678d3f83b1d83a'
  238. 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'
  239. } else if (thirdpart === 'tencent') {
  240. client_id = '101322838'
  241. url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&state=QQ-BIND&client_id=' + client_id + '&redirect_uri=' + redirect_uri
  242. } else if (thirdpart === 'gitee') {
  243. client_id = '235ce26bbc59565b82c989aa3a407ce844cf59a7c5e0f9caa9bb3bf32cee5952'
  244. url = 'https://gitee.com/oauth/authorize?response_type=code&state=GITEE-BIND&client_id=' + client_id + '&redirect_uri=' + redirect_uri
  245. } else if (thirdpart === 'osc') {
  246. client_id = 'neIIqlwGsjsfsA6uxNqD'
  247. url = 'https://www.oschina.net/action/oauth2/authorize?response_type=code&client_id=' + client_id + '&state=OSC-BIND&redirect_uri=' + redirect_uri
  248. }
  249. openWindow(url, thirdpart, 540, 540)
  250. },
  251. handleAvatarSuccess(res, file) {
  252. this.avatarUrl = URL.createObjectURL(file.raw)
  253. this.ruleForm2.avatar = res.data.bucketName + '-' + res.data.fileName
  254. }
  255. }
  256. }
  257. </script>
  258. <style>
  259. .avatar-uploader .el-upload {
  260. border: 1px dashed #d9d9d9;
  261. border-radius: 6px;
  262. cursor: pointer;
  263. position: relative;
  264. overflow: hidden;
  265. }
  266. .avatar-uploader .el-upload:hover {
  267. border-color: #409EFF;
  268. }
  269. .avatar-uploader-icon {
  270. font-size: 28px !important;
  271. color: #8c939d !important;
  272. width: 178px !important;
  273. height: 178px !important;
  274. line-height: 178px !important;
  275. text-align: center !important;
  276. }
  277. .avatar {
  278. width: 178px;
  279. height: 178px;
  280. display: block;
  281. }
  282. </style>