forgetPassword.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <script>
  2. import { resetPassword, sendMsg } from '@/api/newLogin.js'
  3. export default {
  4. data() {
  5. return {
  6. phone: '', code: '',
  7. countdown: 60,
  8. // 整体8-20位,只能大小写+数字
  9. regPwd: /^[A-Za-z0-9]{8,20}$/,
  10. isPwdHide: true,
  11. isBinding: false,
  12. password: '',
  13. }
  14. },
  15. computed: {
  16. canGetCode() {
  17. return !this.isSendingCode && this.countdown === 60
  18. },
  19. canBind() {
  20. return this.code && this.code.length === 6 && !this.isBinding
  21. }
  22. },
  23. onLoad(options) {
  24. if (options.phone) {
  25. this.phone = options.phone;
  26. }
  27. },
  28. watch: {
  29. password(val) {
  30. // 只保留字母+数字,其余全部删除
  31. let filterStr = val.replace(/[^A-Za-z0-9]/g, '')
  32. filterStr = filterStr.slice(0, 20)
  33. // 不一致就强制覆盖,删掉#
  34. if (filterStr !== val) {
  35. //this.$set(this.password,filterStr)
  36. this.$nextTick(() => {
  37. this.password = filterStr
  38. });
  39. }
  40. }
  41. },
  42. methods: {
  43. validatePhone(phone) {
  44. const reg = /^1[3-9]\d{9}$/
  45. return reg.test(phone)
  46. },
  47. getCode() {
  48. if (this.isSendingCode || this.countdown < 60) return
  49. this.isSendingCode = true
  50. sendMsg({ phone: this.phone }).then(res => {
  51. console.log(res)
  52. uni.showToast({
  53. title: '验证码已发送',
  54. icon: 'success'
  55. })
  56. this.startCountdown()
  57. this.isSendingCode = false
  58. })
  59. },
  60. startCountdown() {
  61. this.countdown = 60
  62. this.timer = setInterval(() => {
  63. this.countdown--
  64. if (this.countdown <= 0) {
  65. clearInterval(this.timer)
  66. this.countdown = 60
  67. this.timer = null
  68. }
  69. }, 1000)
  70. },
  71. // handleInputFilter(val) {
  72. // // 过滤掉非字母、数字字符
  73. // const filterStr = val.replace(/[^A-Za-z0-9]/g, "");
  74. // // 限制最大20位
  75. // this.password = filterStr.slice(0, 20);
  76. // },
  77. submitFun() {
  78. if (!this.code) {
  79. uni.showToast({
  80. title: '请输入验证码',
  81. icon: 'none'
  82. })
  83. return
  84. }
  85. if (!this.password) {
  86. uni.showToast({
  87. title: '请输入新密码',
  88. icon: 'none'
  89. })
  90. return
  91. }
  92. // 2.位数+格式校验:8~20位字母数字
  93. if (!this.regPwd.test(this.password) || this.password.length < 8) {
  94. uni.showToast({ title: "请输入8-20位数字/字母组合", icon: "none" });
  95. return;
  96. }
  97. uni.showToast({
  98. title: '验证成功',
  99. icon: 'none'
  100. })
  101. resetPassword({
  102. //openId: uni.getStorageSync('wx_copenid'),
  103. userType: '2',
  104. phone: this.phone,
  105. codeSwitch: 'false',//是否开启验证码登录 true-是 false-否
  106. phoneMsg: this.code,
  107. passWord: this.password
  108. }).then(res => {
  109. if (res.data.code == 200) {
  110. // uni.showToast({
  111. // title: '登录成功',
  112. // icon: 'success'
  113. // })
  114. this.back()
  115. }
  116. })
  117. },
  118. back() {
  119. let pages = getCurrentPages();
  120. if (pages.length >= 2) {
  121. let prevPage = pages[pages.length - 2];
  122. let prevRoute = prevPage.route;
  123. if (prevRoute && prevRoute !== 'pages/index/index') {
  124. if (prevRoute.startsWith('pages/')) {
  125. uni.switchTab({
  126. url: '/' + prevRoute
  127. })
  128. } else {
  129. uni.navigateBack({
  130. delta: 1,
  131. fail: () => {
  132. uni.switchTab({
  133. url: '/pages/index/index'
  134. })
  135. }
  136. })
  137. }
  138. } else {
  139. uni.switchTab({
  140. url: '/pages/index/index'
  141. })
  142. }
  143. } else {
  144. uni.switchTab({
  145. url: '/pages/index/index'
  146. })
  147. }
  148. },
  149. },
  150. beforeDestroy() {
  151. if (this.timer) {
  152. clearInterval(this.timer)
  153. this.timer = null
  154. }
  155. }
  156. }
  157. </script>
  158. <template>
  159. <view class="sett-box">
  160. <input type="text" name="username" style="position:absolute;opacity:0;width:0;height:0;z-index:-99;" />
  161. <input type="password" name="password" style="position:absolute;opacity:0;width:0;height:0;z-index:-99;" />
  162. <view class="greeting-area">
  163. </view>
  164. <view class="greeting-area1"></view>
  165. <view class="content">
  166. <view class="input-box">
  167. <u-input v-model="phone" disabled="true" border="none" placeholder="" class="input-item">
  168. <template slot="prefix">
  169. <view class="label">
  170. <text>手机号</text>
  171. </view>
  172. </template>
  173. </u-input>
  174. </view>
  175. <view class="input-box">
  176. <u-input v-model="code" type="number" border="none" maxlength="6" placeholder="" placeholder-style="color: #999"
  177. class="input-item">
  178. <template slot="prefix">
  179. <view class="label">
  180. <text>验证码</text>
  181. </view>
  182. </template>
  183. </u-input>
  184. <view class="code-btn" :class="{ disabled: !canGetCode }" @click="getCode">
  185. <text v-if="countdown === 60">获取验证码</text>
  186. <text v-else>{{ countdown }}s 后重新获取</text>
  187. </view>
  188. </view>
  189. <view class="input-box">
  190. <u-input v-model="password" autocomplete="off" border="none" :password="isPwdHide" maxlength="20"
  191. placeholder="8-20位数字/字母组合" placeholder-style="font-weight: 400;font-size: 30rpx;color: #C9CDD4;"
  192. class="input-item">
  193. <template slot="prefix">
  194. <view class="label">
  195. <text>新密码</text>
  196. </view>
  197. </template>
  198. <template #suffix>
  199. <image src="/static/login/closeEye.png" @click="isPwdHide = !isPwdHide" class="captcha-img"></image>
  200. <!-- <u-icon :name="isPwdHide ? 'eye-off' : 'eye'" @click="isPwdHide = !isPwdHide" size="32rpx" color="#999" /> -->
  201. </template>
  202. </u-input>
  203. </view>
  204. <view class="bind-btn">
  205. <u-button :loading="isBinding" type="primary" @click="submitFun">确定</u-button>
  206. </view>
  207. </view>
  208. </view>
  209. </template>
  210. <style scoped lang="scss">
  211. ::v-deep .u-input__content {
  212. background-color: #ffffff00 !important;
  213. }
  214. .sett-box {
  215. background: #ffffff;
  216. width: 100%;
  217. min-height: 100vh;
  218. line-height: 1;
  219. position: relative;
  220. //padding: 36rpx 40rpx;
  221. .greeting-area1 {
  222. height: 196rpx;
  223. }
  224. .content {
  225. position: relative;
  226. padding: 0 64rpx;
  227. }
  228. .greeting-area {
  229. background-image: url('/static/login/loginBg.png');
  230. background-size: 100%;
  231. background-repeat: no-repeat;
  232. padding-left: 64rpx;
  233. padding-top: 256rpx;
  234. top: 0;
  235. z-index: 0 !important;
  236. height: 438rpx;
  237. position: absolute;
  238. overflow: hidden;
  239. width: 100%;
  240. .bubble-text {
  241. font-weight: 500;
  242. font-size: 52rpx;
  243. color: #1D2129
  244. }
  245. }
  246. .code-btn {
  247. font-weight: 400;
  248. font-size: 30rpx;
  249. color: #19D29B;
  250. text-align: center;
  251. font-style: normal;
  252. text-transform: none;
  253. }
  254. }
  255. .input-box {
  256. width: 622rpx;
  257. height: 110rpx;
  258. background: #ffffff00!important;
  259. display: flex;
  260. align-items: center;
  261. border-bottom: 1rpx solid #E7E7E7;
  262. .u-input{
  263. background: #ffffff00!important;
  264. }
  265. .label {
  266. display: flex;
  267. font-weight: 400;
  268. font-size: 30rpx;
  269. color: #1D2129;
  270. text-align: center;
  271. margin-right: 30rpx;
  272. }
  273. .input-item {
  274. flex: 1;
  275. }
  276. .captcha-img{
  277. width: 30rpx;
  278. height: 30rpx;
  279. }
  280. ::v-deep .uni-input-input {
  281. font-weight: 500;
  282. font-size: 30rpx;
  283. color: #1D2129;
  284. }
  285. }
  286. .bind-btn {
  287. margin-top: 80rpx;
  288. ::v-deep .u-button {
  289. width: 622rpx;
  290. height: 88rpx;
  291. background: linear-gradient(263deg, #45FFD7 0%, #7FFFBD 100%);
  292. border-radius: 60rpx 60rpx 60rpx 60rpx;
  293. border: none;
  294. font-weight: 500;
  295. font-size: 32rpx;
  296. color: #1D2129;
  297. text-align: center;
  298. }
  299. ::v-deep .u-button--disabled {
  300. background: #E0E0E0 !important;
  301. color: #999 !important;
  302. }
  303. }
  304. </style>