forgetPassword.vue 11 KB

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