info.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. <el-row>
  21. <el-col :span="12">
  22. <div class="grid-content bg-purple">
  23. <el-form :model="ruleForm2"
  24. :rules="rules2"
  25. ref="ruleForm2"
  26. label-width="100px"
  27. class="demo-ruleForm">
  28. <el-form-item label="用户名"
  29. prop="username">
  30. <el-input type="text"
  31. :value="userInfo.username"
  32. disabled></el-input>
  33. </el-form-item>
  34. <el-form-item label="原密码"
  35. prop="password">
  36. <el-input type="password"
  37. v-model="ruleForm2.password"
  38. auto-complete="off"></el-input>
  39. </el-form-item>
  40. <el-form-item label="密码"
  41. prop="newpassword1">
  42. <el-input type="password"
  43. v-model="ruleForm2.newpassword1"
  44. auto-complete="off"></el-input>
  45. </el-form-item>
  46. <el-form-item label="确认密码"
  47. prop="newpassword2">
  48. <el-input type="password"
  49. v-model="ruleForm2.newpassword2"
  50. auto-complete="off"></el-input>
  51. </el-form-item>
  52. <el-form-item label="社交登录"
  53. prop="social">
  54. <a href="#"
  55. style="color: blue"
  56. @click="handleClick('wechat')">绑定微信</a>
  57. </el-form-item>
  58. <el-form-item>
  59. <el-button type="primary"
  60. @click="submitForm('ruleForm2')">提交</el-button>
  61. <el-button @click="resetForm('ruleForm2')">重置</el-button>
  62. </el-form-item>
  63. </el-form>
  64. </div>
  65. </el-col>
  66. </el-row>
  67. </basic-container>
  68. </div>
  69. </template>
  70. <script>
  71. import { openWindow } from '@/util/util'
  72. import { mapState } from 'vuex'
  73. import { getToken } from '@/util/auth'
  74. import ElFormItem from 'element-ui/packages/form/src/form-item.vue'
  75. import request from '@/router/axios'
  76. export default {
  77. components: {
  78. ElFormItem
  79. },
  80. data () {
  81. var validatePass = (rule, value, callback) => {
  82. if (this.ruleForm2.password !== '') {
  83. if (value === '') {
  84. callback(new Error('请再次输入密码'))
  85. } else if (value !== this.ruleForm2.newpassword1) {
  86. callback(new Error('两次输入密码不一致!'))
  87. } else {
  88. callback()
  89. }
  90. } else {
  91. callback()
  92. }
  93. }
  94. return {
  95. fileList: [],
  96. show: false,
  97. headers: {
  98. Authorization: 'Bearer ' + getToken()
  99. },
  100. ruleForm2: {
  101. password: '',
  102. newpassword1: '',
  103. newpassword2: ''
  104. },
  105. rules2: {
  106. password: [{ required: true, min: 6, message: '原密码不能为空且不少于6位', trigger: 'change' }],
  107. newpassword1: [{ required: true, min: 6, message: '新密码不能为空且不少于6位', trigger: 'change' }],
  108. newpassword2: [{ required: true, validator: validatePass, trigger: 'blur' }]
  109. }
  110. }
  111. },
  112. created () {
  113. },
  114. computed: {
  115. ...mapState({
  116. userInfo: state => state.user.userInfo
  117. })
  118. },
  119. methods: {
  120. submitForm (formName) {
  121. this.$refs[formName].validate(valid => {
  122. if (valid) {
  123. request({
  124. url: '/admin/user/editInfo',
  125. method: 'put',
  126. data: this.ruleForm2
  127. }).then(response => {
  128. if (response.data.data) {
  129. this.$notify({
  130. title: '成功',
  131. message: '修改成功',
  132. type: 'success',
  133. duration: 2000
  134. })
  135. // 修改密码之后强制重新登录
  136. if (this.ruleForm2.newpassword1 !== '') {
  137. this.$store.dispatch('LogOut').then(() => {
  138. location.reload() // 为了重新实例化vue-router对象 避免bug
  139. })
  140. } else {
  141. this.$router.push({ path: '/' })
  142. }
  143. } else {
  144. this.$notify({
  145. title: '失败',
  146. message: response.data.msg,
  147. type: 'error',
  148. duration: 2000
  149. })
  150. }
  151. })
  152. .catch(() => {
  153. this.$notify({
  154. title: '失败',
  155. message: '修改失败',
  156. type: 'error',
  157. duration: 2000
  158. })
  159. })
  160. } else {
  161. return false
  162. }
  163. })
  164. },
  165. resetForm (formName) {
  166. this.$refs[formName].resetFields()
  167. },
  168. toggleShow () {
  169. this.show = !this.show
  170. },
  171. /**
  172. * upload success
  173. *
  174. * [param] jsonData 服务器返回数据,已进行json转码
  175. * [param] field
  176. */
  177. cropUploadSuccess (jsonData) {
  178. this.$store.commit('SET_AVATAR', jsonData.filename)
  179. },
  180. handleClick (thirdpart) {
  181. let appid, client_id, redirect_uri, url
  182. redirect_uri = encodeURIComponent(window.location.origin + '/#/authredirect?type=BIND')
  183. if (thirdpart === 'wechat') {
  184. appid = 'wxd1678d3f83b1d83a'
  185. url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&state=' + appid + '&response_type=code&scope=snsapi_login#wechat_redirect'
  186. } else if (thirdpart === 'tencent') {
  187. client_id = '101322838'
  188. url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&state=' + appid + '&client_id=' + client_id + '&redirect_uri=' + redirect_uri
  189. }
  190. openWindow(url, thirdpart, 540, 540)
  191. }
  192. }
  193. }
  194. </script>