pwd.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view>
  3. <uni-nav-bar id="nav-bar" status-bar="true" @clickLeft="onBack()" :title="bModifyPassword?'修改密码':'设置密码'"
  4. color="#000000" fixed="true" :border="false">
  5. <view slot="left">
  6. <view class=" flex align-center margin-left">
  7. <image class="p-left-arrow" src="../../../static/p-left-arrow.png"></image>
  8. </view>
  9. </view>
  10. <view slot="right">
  11. <view class="make-text-bPurple text-regular margin-right" @click="savePassword">保存</view>
  12. </view>
  13. </uni-nav-bar>
  14. <block v-if="bModifyPassword">
  15. <view class="card-view password-item flex justify-center ">
  16. <m-input inputmode="email" style=" margin-left: 46rpx;" type="text" focus clearable v-model="account"
  17. placeholder="请输入手机号/邮箱">
  18. </m-input>
  19. </view>
  20. <view class="card-view password-item flex justify-center ">
  21. <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable v-model="oldPassword"
  22. placeholder="请输入旧密码">
  23. </m-input>
  24. </view>
  25. <view class="card-view password-item flex justify-center ">
  26. <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable v-model="newPassword"
  27. placeholder="请输入新密码">
  28. </m-input>
  29. </view>
  30. <view class="card-view password-item flex justify-center ">
  31. <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable
  32. v-model="confirmPassword" placeholder="请再次输入新密码">
  33. </m-input>
  34. </view>
  35. </block>
  36. <block v-else>
  37. <view class="card-view password-item flex justify-center ">
  38. <m-input inputmode="email" style=" margin-left: 46rpx;" type="text" focus clearable v-model="account"
  39. placeholder="请输入手机号/邮箱">
  40. </m-input>
  41. </view>
  42. <view class="card-view cu-form-group ">
  43. <view style="width: 16rpx;"></view>
  44. <m-input inputmode="numeric" type="number" focus clearable v-model="verificationCode" placeholder="请输入验证码">
  45. </m-input>
  46. <button v-if="bCodeDisabled" class="cu-btn make-bg-bPurple shadow text-white"
  47. style="background-color: rgb(0,0,0);opacity: 0.5;">
  48. 重新获取({{count}})</button>
  49. <button v-else class="cu-btn make-bg-bPurple shadow text-white" @tap="onGetCode">获取验证码</button>
  50. </view>
  51. <view class="card-view password-item flex justify-center ">
  52. <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable v-model="newPassword"
  53. placeholder="请输入新密码">
  54. </m-input>
  55. </view>
  56. <view class="card-view password-item flex justify-center ">
  57. <m-input inputmode="text" style=" margin-left: 46rpx;" type="password" maxlength="16" displayable
  58. v-model="confirmPassword" placeholder="请确认新密码">
  59. </m-input>
  60. </view>
  61. </block>
  62. <view class="text-red margin-xl text-regular">密码必须是6-18位字符,数字、字母、特殊字符 (不能是纯数字、字母的组合)</view>
  63. </view>
  64. </template>
  65. <script>
  66. import service from '../../../util/util-js/service.js';
  67. import mInput from '../../../components/m-input.vue';
  68. import verify from '../../../util/util-js/verify.js'
  69. import config from '@/common/config.js';
  70. import reqUtil from "@/util/util-js/requstUtil.js";
  71. import {
  72. mapState,
  73. mapMutations
  74. } from 'vuex'
  75. export default {
  76. components: {
  77. mInput
  78. },
  79. data() {
  80. return {
  81. account: '',
  82. oldPassword: '',
  83. newPassword: '',
  84. confirmPassword: '',
  85. verificationCode: '',
  86. bModifyPassword: true,
  87. bModifying: false,
  88. }
  89. },
  90. computed: mapState(['bCodeDisabled', 'count']),
  91. onLoad(option) {
  92. if (option.bModify) {
  93. //设置页面状态
  94. this.bModifyPassword = JSON.parse(option.bModify);
  95. }
  96. },
  97. methods: {
  98. ...mapMutations(['countDown', 'resetCountDown']),
  99. onBack() {
  100. uni.navigateBack({
  101. delta: 1
  102. })
  103. },
  104. onGetCode() {
  105. //置灰状态
  106. if (this.bCodeDisabled) return;
  107. if (!~this.account.indexOf('@')) {
  108. if (!verify.checkPhone(this.account)) {
  109. uni.showToast({
  110. icon: 'none',
  111. title: '请输入正确手机号'
  112. });
  113. return;
  114. }
  115. //调用store 倒计时
  116. this.countDown({
  117. account: this.account,
  118. type: 0
  119. });
  120. } else {
  121. if (!verify.checkEMail(this.account)) {
  122. uni.showToast({
  123. icon: 'none',
  124. title: '请输入正确邮箱号'
  125. });
  126. return;
  127. }
  128. //调用store 倒计时
  129. this.countDown({
  130. account: this.account,
  131. type: 1
  132. });
  133. }
  134. },
  135. savePassword() {
  136. if (this.bModifying) return;
  137. /**
  138. * 同时判断两个类型
  139. */
  140. if (!~this.account.indexOf('@') && !verify.checkPhone(this.account)) {
  141. uni.showToast({
  142. icon: 'none',
  143. title: '手机号不合法',
  144. });
  145. return;
  146. } else if (~this.account.indexOf('@') && !verify.checkEMail(this.account)) {
  147. uni.showToast({
  148. icon: 'none',
  149. title: '邮箱地址不合法',
  150. });
  151. return;
  152. }
  153. if (this.bModifyPassword) {
  154. //如果是修改密码,不需要验证码
  155. if (!verify.checkPassword(this.oldPassword)) {
  156. uni.showToast({
  157. icon: 'none',
  158. title: '旧的密码格式不合法',
  159. });
  160. return;
  161. }
  162. if (!verify.checkPassword(this.newPassword)) {
  163. uni.showToast({
  164. icon: 'none',
  165. title: '新的密码格式不合法',
  166. });
  167. return;
  168. }
  169. } else {
  170. if (this.verificationCode == '' ||
  171. this.verificationCode == undefined ||
  172. this.verificationCode == null) {
  173. uni.showToast({
  174. icon: 'none',
  175. title: '输入验证码',
  176. });
  177. return;
  178. }
  179. if (!verify.checkPassword(this.newPassword)) {
  180. uni.showToast({
  181. icon: 'none',
  182. title: '新的密码格式不合法',
  183. });
  184. return;
  185. }
  186. }
  187. if (!verify.checkPassword(this.confirmPassword)) {
  188. uni.showToast({
  189. icon: 'none',
  190. title: '确认的密码格式不合法',
  191. });
  192. return;
  193. }
  194. if (this.confirmPassword != this.newPassword) {
  195. uni.showToast({
  196. icon: 'none',
  197. title: '请输入两个相同的密码',
  198. });
  199. return;
  200. }
  201. this.bModifying = true;
  202. uni.showToast({
  203. icon: 'loading',
  204. title: '',
  205. duration: 10000
  206. });
  207. //todo 处理新密码
  208. if (this.bModifyPassword) {
  209. //如果是修改密码,不需要验证码
  210. reqUtil.requestData(config.URL.MODIFYPASSWORDFROMACCOUNT, {
  211. "account": this.account,
  212. "type": !~this.account.indexOf('@') ? 0 : 1,
  213. "oldPassword": this.oldPassword,
  214. "newPassword": this.newPassword
  215. }).then(res => {
  216. uni.hideToast();
  217. console.log("MODIFYPASSWORDFROMACCOUNT" + JSON.stringify(res));
  218. if (res.code == 0) {
  219. uni.showToast({
  220. icon: 'success',
  221. title: '设置密码成功',
  222. duration: 2000,
  223. mask: true
  224. });
  225. this.$store.state.setPasswordFirstTime = false;
  226. setTimeout(() => {
  227. this.onBack();
  228. }, 2000);
  229. } else {
  230. uni.showToast({
  231. title: '修改密码失败',
  232. duration: 2000
  233. });
  234. }
  235. this.resetCountDown();
  236. this.bModifying = false;
  237. },
  238. e => {
  239. console.log(e);
  240. this.bModifying = false;
  241. });
  242. } else {
  243. reqUtil.requestData(config.URL.MODIFYPASSWORDFROMSMS, {
  244. "account": this.account,
  245. "type": !~this.account.indexOf('@') ? 0 : 1,
  246. "code": this.verificationCode,
  247. "password": this.newPassword
  248. }).then(res => {
  249. console.log("MODIFYPASSWORDFROMSMS" + JSON.stringify(res));
  250. uni.hideToast();
  251. if (res.code == 0) {
  252. uni.showToast({
  253. icon: 'success',
  254. title: '修改密码成功',
  255. duration: 2000,
  256. mask: true
  257. });
  258. this.$store.state.setPasswordFirstTime = false;
  259. setTimeout(() => {
  260. this.onBack();
  261. }, 2000);
  262. } else {
  263. uni.showToast({
  264. title: '修改密码失败',
  265. duration: 2000
  266. });
  267. }
  268. this.resetCountDown();
  269. this.bModifying = false;
  270. },
  271. e => {
  272. console.log(e);
  273. this.bModifying = false;
  274. });
  275. }
  276. }
  277. }
  278. }
  279. </script>
  280. <style>
  281. .password-item {
  282. height: 100rpx;
  283. }
  284. .card-view {
  285. border-radius: 10px;
  286. }
  287. </style>