findpass.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="pageTop x-c">
  5. <view class="loginBox">
  6. <view class="login-item">
  7. <view class="input-account">
  8. <input v-model="phone" placeholder="手机号" type="text" maxlength="11"/>
  9. </view>
  10. <view class="line"></view>
  11. </view>
  12. <view class="login-item">
  13. <view class="input-pwd">
  14. <input v-model="newPassword" placeholder="新密码(6-15个字符)" type="password" />
  15. </view>
  16. <view class="line"></view>
  17. </view>
  18. <view class="login-item">
  19. <view class="input-pwd">
  20. <input v-model="confirmPassword" placeholder="确认密码" type="password" />
  21. </view>
  22. <view class="line"></view>
  23. </view>
  24. <view class="login-item">
  25. <view class="input-yzcode x-bc">
  26. <input v-model="code" placeholder="验证码" type="number" />
  27. <view style="color:#666;flex-shrink: 0;" @click="sendSms">
  28. {{coolDown==0 ? '获取验证码': `${coolDown}秒后重试`}}
  29. </view>
  30. </view>
  31. <view class="line"></view>
  32. </view>
  33. <view class="btns">
  34. <view class="login-btn" @click="resetPasswordLogin">设置新密码</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. login,
  44. getUserInfo,
  45. sendCode,
  46. resetPassword
  47. } from '@/api/user'
  48. export default {
  49. data() {
  50. return {
  51. //userName:"CEadmin01",
  52. //password:"ADMIN01",
  53. phone: "",
  54. code: "",
  55. newPassword: "",
  56. confirmPassword: "",
  57. coolDown: 0,
  58. timer: null,
  59. btnLoading: false
  60. }
  61. },
  62. onLoad(option) {
  63. let that = this;
  64. uni.$on('getRegistrationID', function(data) {
  65. that.registrationID = data;
  66. });
  67. this.$getRegistrationID();
  68. this.btnLoading = false
  69. },
  70. onShow() {
  71. },
  72. onUnload() {
  73. uni.$off('getRegistrationID');
  74. },
  75. mounted() {
  76. },
  77. methods: {
  78. resetPasswordLogin() {
  79. if(this.btnLoading) return
  80. if (!uni.$u.test.mobile(this.phone)) {
  81. uni.showToast({
  82. title: "请输入正确的手机号",
  83. icon: 'none',
  84. });
  85. return
  86. }
  87. if (this.$isEmpty(this.newPassword)) {
  88. uni.showToast({
  89. title: "请输入新密码",
  90. icon: 'none',
  91. });
  92. return
  93. }
  94. if (this.newPassword.length<6||this.newPassword.length>15 ) {
  95. uni.showToast({
  96. title: "密码长度应该在6到15个字符",
  97. icon: 'none',
  98. });
  99. return
  100. }
  101. if (this.$isEmpty(this.confirmPassword)) {
  102. uni.showToast({
  103. title: "请输入确认密码",
  104. icon: 'none',
  105. });
  106. return
  107. }
  108. if (this.newPassword!=this.confirmPassword) {
  109. uni.showToast({
  110. title: "两次输入密码不一致",
  111. icon: 'none',
  112. });
  113. return
  114. }
  115. if (this.$isEmpty(this.code)) {
  116. uni.showToast({
  117. title: "请输入验证码",
  118. icon: 'none',
  119. });
  120. return
  121. }
  122. this.btnLoading = true
  123. const param = {
  124. phone: this.phone,
  125. code: this.code,
  126. newPassword: this.newPassword,
  127. confirmPassword: this.confirmPassword,
  128. }
  129. resetPassword(param).then(res=>{
  130. this.btnLoading = false
  131. if(res.code == 200) {
  132. uni.showToast({
  133. title: '设置成功',
  134. icon: 'none',
  135. });
  136. setTimeout(()=>{
  137. uni.redirectTo({
  138. url: '/pages/auth/login'
  139. })
  140. },1500)
  141. } else {
  142. uni.showToast({
  143. title: res.msg,
  144. icon: 'none',
  145. });
  146. }
  147. }).catch(()=>{
  148. this.btnLoading = false
  149. })
  150. },
  151. sendSms() {
  152. if (this.coolDown > 0) {
  153. return
  154. }
  155. if (!uni.$u.test.mobile(this.phone)) {
  156. uni.showToast({
  157. title: "请输入正确的手机号",
  158. icon: 'none',
  159. });
  160. return
  161. }
  162. console.log(uni.$u.test.mobile(this.phone))
  163. this.coolDown = 60;
  164. sendCode({
  165. phone: this.phone
  166. }).then(res => {
  167. if (res.code == 200) {
  168. uni.showToast({
  169. title: '验证码已发送',
  170. icon: 'none',
  171. });
  172. this.coolDown = 60;
  173. this.timer = setInterval(() => {
  174. this.coolDown--;
  175. if (this.coolDown === 0) {
  176. clearInterval(this.timer);
  177. this.timer = null;
  178. }
  179. }, 1000);
  180. } else {
  181. this.timer && clearInterval(this.timer);
  182. this.coolDown = 0
  183. uni.showToast({
  184. title: res.msg,
  185. icon: 'none',
  186. });
  187. }
  188. },
  189. rej => {
  190. this.timer && clearInterval(this.timer);
  191. this.coolDown = 0;
  192. }).catch(() => {
  193. this.timer && clearInterval(this.timer);
  194. this.coolDown = 0;
  195. })
  196. },
  197. login() {
  198. if (this.$isEmpty(this.userName)) {
  199. uni.showToast({
  200. title: "请输入帐号",
  201. icon: 'none',
  202. });
  203. return
  204. }
  205. if (this.$isEmpty(this.password)) {
  206. uni.showToast({
  207. title: "请输入密码",
  208. icon: 'none',
  209. });
  210. return
  211. }
  212. var data = {
  213. userName: this.userName,
  214. password: this.password,
  215. jpushId: this.registrationID || uni.getStorageSync("registrationID")
  216. };
  217. var that = this;
  218. uni.showLoading({
  219. title: "处理中..."
  220. });
  221. login(data).then(res => {
  222. uni.hideLoading()
  223. if (res.code == 200) {
  224. // #ifdef APP-PLUS
  225. //const jyJPush = uni.requireNativePlugin('JY-JPush');
  226. // #endif
  227. uni.setStorageSync('AppToken', res.data.token);
  228. this.$Router.pushTab({
  229. name: 'home'
  230. });
  231. } else {
  232. uni.showToast({
  233. title: res.msg,
  234. icon: 'none'
  235. });
  236. }
  237. },
  238. rej => {}
  239. );
  240. },
  241. goToRegister() {
  242. this.$navTo('./register');
  243. },
  244. goToFindPass() {
  245. this.$navTo('./findPass');
  246. },
  247. getRegistrationID() {
  248. // #ifdef APP-PLUS
  249. // #endif
  250. }
  251. },
  252. beforeDestroy() { // 组件卸载时清掉定时器,防止内存泄漏
  253. this.timer && clearInterval(this.timer);
  254. }
  255. }
  256. </script>
  257. <style lang="scss">
  258. page {
  259. background-color: #ffffff;
  260. }
  261. .content {
  262. display: flex;
  263. flex-direction: column;
  264. align-items: center;
  265. height: calc(100vh);
  266. width: 100%;
  267. justify-content: space-between;
  268. //padding-top: calc(100% - 32vh);
  269. }
  270. .pageTop {
  271. display: flex;
  272. flex-direction: column;
  273. width: 100%;
  274. }
  275. .content .head {
  276. text-align: center;
  277. width: 100%;
  278. height: 522rpx;
  279. background: url(/static/image/login/top_bg.png) no-repeat 0 center;
  280. background-size: cover;
  281. box-sizing: border-box;
  282. }
  283. .content .head image {
  284. width: 150rpx;
  285. height: 150rpx;
  286. border-radius: 10rpx;
  287. box-shadow: 0px 0px 20rpx rgba(0, 0, 0, 0.2);
  288. }
  289. .title {
  290. color: #141414;
  291. margin: 50upx 0upx 30upx 0rpx;
  292. font-size: 38rpx;
  293. font-weight: 500;
  294. }
  295. .desc {
  296. color: #686866;
  297. padding: 0 0 30rpx 0rpx;
  298. font-size: 28rpx;
  299. }
  300. .loginBox {
  301. padding: 10px 10px 30rpx;
  302. width: calc(100% - 20px);
  303. margin-top: 0rpx;
  304. background: #FDFDFD;
  305. //box-shadow: 0rpx 4rpx 27rpx 0rpx rgba(155,155,155,0.25);
  306. border-radius: 7rpx;
  307. }
  308. .login-item p {
  309. text-align: left;
  310. }
  311. .line {
  312. height: 0.5rpx;
  313. background-color: #efefef;
  314. margin-top: 10rpx;
  315. }
  316. .input-account {
  317. margin-top: 20rpx;
  318. margin-bottom: 0rpx;
  319. border-radius: 40rpx;
  320. border: solid 0rpx #efefef;
  321. height: 80rpx;
  322. width: 100%;
  323. background: url(/static/account.png) no-repeat 0 center;
  324. background-size: 30rpx 30rpx;
  325. background-position: 30rpx;
  326. }
  327. .input-yzcode {
  328. margin-top: 20rpx;
  329. margin-bottom: 0rpx;
  330. border-radius: 40rpx;
  331. border: solid 0rpx #efefef;
  332. height: 80rpx;
  333. width: 100%;
  334. background: url(/static/image/login/cz_icon.png) no-repeat 0 center;
  335. background-size: 30rpx 30rpx;
  336. background-position: 30rpx;
  337. }
  338. .input-pwd {
  339. margin-top: 40rpx;
  340. margin-bottom: 20rpx;
  341. border-radius: 40rpx;
  342. border: solid 0rpx #efefef;
  343. height: 80rpx;
  344. width: 100%;
  345. background: url(/static/password.png) no-repeat 0 center;
  346. background-size: 30rpx 30rpx;
  347. background-position: 30rpx;
  348. }
  349. input {
  350. margin-left: 80rpx;
  351. height: 80rpx;
  352. line-height: 80rpx
  353. }
  354. .footer {
  355. color: #686866;
  356. width: 100%;
  357. position: fixed;
  358. text-align: center;
  359. bottom: 60upx;
  360. font-size: 28rpx;
  361. }
  362. .btns {
  363. margin: 60rpx 0rpx;
  364. }
  365. .login-btn {
  366. display: flex;
  367. align-items: center;
  368. justify-content: center;
  369. width: 100%;
  370. height: 80rpx;
  371. background: linear-gradient(to right, #FF5C03 0%, #FF5C03 100%);
  372. background: -moz-linear-gradient(to right, #FF5C03 0%, #FF5C03 100%);
  373. box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  374. border-radius: 40rpx;
  375. font-size: 30rpx;
  376. font-family: PingFang SC;
  377. font-weight: 500;
  378. color: rgba(255, 255, 255, 1);
  379. }
  380. .reg-box {
  381. padding-bottom: 20rpx;
  382. margin: 0 10px;
  383. .reg-btn {
  384. font-size: 16px;
  385. color: #FF5C03;
  386. }
  387. }
  388. .pageBottom {
  389. height: 260rpx;
  390. width: 75%;
  391. display: flex;
  392. flex-direction: column;
  393. }
  394. .tips {
  395. color: #999;
  396. font-size: 36rpx;
  397. }
  398. .menu {
  399. margin-top: 30rpx;
  400. image {
  401. width: 78rpx;
  402. height: 78rpx;
  403. }
  404. }
  405. </style>