password-modal.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <u-popup :show="popShow" @close="cancel" mode="center" :is-mask-click="false">
  3. <view class="popup-wrapper">
  4. <view class="title">服务器设置</view>
  5. <u-form labelPosition="left" labelAlign="right" :model="formData" :rules="rules" ref="formRef"
  6. label-width="150">
  7. <u-form-item label="旧密码" prop="oldPassword" class="form-required">
  8. <u-input v-model="formData.oldPassword" placeholder="输入" type="password">
  9. </u-input>
  10. </u-form-item>
  11. <u-form-item label="新密码" prop="newPassword" class="form-required">
  12. <u-input v-model="formData.newPassword" placeholder="输入" type="password">
  13. </u-input>
  14. </u-form-item>
  15. <u-form-item label="确认密码" prop="newPassword1" class="form-required">
  16. <u-input v-model="formData.newPassword1" placeholder="输入" type="password">
  17. </u-input>
  18. </u-form-item>
  19. </u-form>
  20. <view class="footer">
  21. <u-button size="small" @click="cancel">取消</u-button>
  22. <u-button size="small" type="success" @click="confirm">确定</u-button>
  23. </view>
  24. </view>
  25. </u-popup>
  26. </template>
  27. <script>
  28. import {
  29. updatePassword
  30. } from '@/api/common.js'
  31. export default {
  32. data() {
  33. return {
  34. popShow: false,
  35. formData: {
  36. oldPassword: '',
  37. newPassword: '',
  38. newPassword1: ''
  39. },
  40. rules: {
  41. oldPassword: {
  42. type: 'string',
  43. required: true,
  44. message: '请输入旧密码',
  45. trigger: ['blur']
  46. },
  47. newPassword: {
  48. type: 'string',
  49. required: true,
  50. message: '请输入新密码',
  51. trigger: ['blur']
  52. },
  53. newPassword1: [{
  54. required: true,
  55. type: 'string',
  56. trigger: ['blur'],
  57. validator: (_rule, value, callback) => {
  58. if (!value) {
  59. return callback(new Error('请再次输入新密码'));
  60. }
  61. if (value !== this.formData.newPassword) {
  62. return callback(new Error('两次输入密码不一致'));
  63. }
  64. callback();
  65. }
  66. }]
  67. }
  68. }
  69. },
  70. created() {
  71. },
  72. methods: {
  73. open() {
  74. this.popShow = true
  75. },
  76. cancel() {
  77. this.popShow = false
  78. },
  79. loginOut() {
  80. uni.showModal({
  81. title: '提示',
  82. content: '确认退出登录',
  83. success: res => {
  84. console.log(res, res.confirm, '-----确认退出登录');
  85. if (res.confirm) {
  86. console.log('-----确认退出登录9999999');
  87. try {
  88. postJ(this.apiUrl + '/main/user/logout')
  89. .then(res => {
  90. uni.showToast({
  91. title: '退出成功',
  92. icon: 'success',
  93. duration: 500
  94. })
  95. setTimeout(() => {
  96. uni.clearStorage()
  97. uni.removeStorageSync('token')
  98. uni.removeStorageSync('userInfo')
  99. uni.removeStorageSync('treeList')
  100. uni.reLaunch({
  101. url: '/pages/login/login'
  102. })
  103. }, 500)
  104. })
  105. .catch(err => {
  106. console.log(err);
  107. uni.showToast({
  108. title: '退出失败',
  109. icon: 'none'
  110. })
  111. })
  112. } catch (error) {
  113. console.log(error, 'error----')
  114. uni.reLaunch({
  115. url: '/pages/login/login'
  116. })
  117. }
  118. } else if (res.cancel) {
  119. console.log('用户点击取消')
  120. }
  121. }
  122. })
  123. },
  124. confirm() {
  125. const userInfo = uni.getStorageSync("userInfo");
  126. this.$refs.formRef
  127. .validate()
  128. .then(res => {
  129. // Vue.prototype.apiWebUrl =
  130. // `${this.formData.protocal}${this.formData.hostname}:${this.formData.port}/web`
  131. // Vue.prototype.apiUrl =
  132. // `${this.formData.protocal}${this.formData.hostname}:${this.formData.port}/api`
  133. // Vue.prototype.webviewUrl =
  134. // `${this.formData.protocal}${this.formData.hostname}:${this.formData.port}`
  135. // uni.setStorageSync('apiInfo', this.formData)
  136. // this.$emit('setServerStatus', true)
  137. // this.cancel()
  138. this.formData.id = userInfo.userId
  139. updatePassword(this.formData).then(res => {
  140. if (res == 1) {
  141. uni.$u.toast('密码修改成功')
  142. setTimeout(() => {
  143. uni.removeStorageSync('token')
  144. uni.removeStorageSync('userInfo')
  145. uni.removeStorageSync('treeList')
  146. uni.reLaunch({
  147. url: '/pages/login/login'
  148. })
  149. }, 500)
  150. }
  151. })
  152. })
  153. .catch(errors => {
  154. uni.$u.toast('校验失败')
  155. })
  156. }
  157. }
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. .popup-wrapper {
  162. padding: 0 20rpx;
  163. .title {
  164. text-align: center;
  165. font-weight: bold;
  166. padding: 20rpx;
  167. }
  168. /deep/.u-form {
  169. .u-input__content__field-wrapper__field,
  170. .u-form-item__body__left__content__label {
  171. font-size: 28rpx !important;
  172. }
  173. .u-form-item__body__right__content__slot {}
  174. }
  175. /deep/.uni-stat__select {
  176. // height: 76rpx !important;
  177. width: 150rpx;
  178. flex: 0;
  179. .uni-select {
  180. width: 150rpx;
  181. font-size: 28rpx !important;
  182. }
  183. .uni-stat-box,
  184. .uni-select__input-box {
  185. // height: 76rpx !important;
  186. }
  187. }
  188. /deep/.u-input {
  189. flex: 1;
  190. padding: 12rpx 18rpx !important;
  191. border: 1px solid #e5e5e5;
  192. }
  193. .footer {
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. padding: 20rpx 0;
  198. .u-button+.u-button {
  199. margin-left: 20rpx;
  200. }
  201. }
  202. }
  203. </style>