forget.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view style="height: 100%">
  3. <image
  4. mode="widthFix"
  5. src="/pages2/static/login_bg.jpg"
  6. class="full_img"
  7. ></image>
  8. <u-navbar
  9. title="忘记密码"
  10. :border-bottom="false"
  11. background="{ background: '#ffffff',opacity:0.4; }"
  12. title-color="#ffffff"
  13. back-icon-color="#ffffff"
  14. ></u-navbar>
  15. <view style="padding: 30rpx">
  16. <view class="login_box">
  17. <u-form :model="form" ref="uForm">
  18. <u-form-item prop="tel" ref="tel"
  19. ><u-input
  20. v-model="form.tel"
  21. type="number"
  22. maxlength="11"
  23. placeholder-style="color:#999999"
  24. placeholder="手机号"
  25. /></u-form-item>
  26. <u-form-item prop="code">
  27. <u-input
  28. v-model="form.code"
  29. type="number"
  30. placeholder-style="color:#999999"
  31. placeholder="验证码"
  32. />
  33. <u-button slot="right" size="mini" @click="getCode">{{
  34. codeTips
  35. }}</u-button>
  36. </u-form-item>
  37. <u-form-item prop="pwd"
  38. ><u-input
  39. class="password"
  40. placeholder-style="color:#999999"
  41. v-model="form.pwd"
  42. type="password"
  43. placeholder="请输入新密码"
  44. /></u-form-item>
  45. <u-form-item prop="pwdAgain"
  46. ><u-input
  47. class="password"
  48. placeholder-style="color:#999999"
  49. v-model="form.pwdAgain"
  50. type="password"
  51. placeholder="再次输入新密码"
  52. /></u-form-item>
  53. </u-form>
  54. </view>
  55. <button
  56. :disabled="isUse"
  57. class="loginBtn"
  58. :class="{ able: canSubmit() }"
  59. @click="submit"
  60. >
  61. 确定
  62. </button>
  63. </view>
  64. <u-verification-code
  65. seconds="60"
  66. ref="uCode"
  67. @change="codeChange"
  68. ></u-verification-code>
  69. </view>
  70. </template>
  71. <script>
  72. export default {
  73. data() {
  74. return {
  75. code: "",
  76. form: {
  77. code: "",
  78. tel: "",
  79. pwd: "",
  80. pwdAgain: "",
  81. },
  82. rules: {
  83. tel: [
  84. {
  85. required: true,
  86. message: "请输入手机号",
  87. // 可以单个或者同时写两个触发验证方式
  88. trigger: ["change"],
  89. },
  90. {
  91. validator: (rule, value, callback) => {
  92. // 上面有说,返回true表示校验通过,返回false表示不通过
  93. // this.$u.test.mobile()就是返回true或者false的
  94. return this.$u.test.mobile(value);
  95. },
  96. message: "手机号码格式不正确",
  97. // 触发器可以同时用blur和change
  98. trigger: ["change"],
  99. },
  100. ],
  101. pwd: [
  102. {
  103. required: true,
  104. message: "请输入密码",
  105. // 可以单个或者同时写两个触发验证方式
  106. trigger: ["change"],
  107. },
  108. ],
  109. pwdAgain: [
  110. {
  111. required: true,
  112. message: "请输入密码",
  113. // 可以单个或者同时写两个触发验证方式
  114. trigger: ["change"],
  115. },
  116. ],
  117. code: [
  118. {
  119. required: true,
  120. message: "请输入验证码",
  121. // 可以单个或者同时写两个触发验证方式
  122. trigger: ["change"],
  123. },
  124. ],
  125. },
  126. codeTips: "",
  127. read: "",
  128. isUse: false,
  129. };
  130. },
  131. methods: {
  132. canSubmit() {
  133. if (
  134. this.form.tel &&
  135. this.form.code &&
  136. this.form.pwd &&
  137. this.form.pwdAgain
  138. ) {
  139. return true;
  140. }
  141. return false;
  142. },
  143. submit() {
  144. let that = this;
  145. if (!this.form.tel) {
  146. this.$u.toast("请输入手机号码");
  147. return;
  148. }
  149. if (!this.form.code) {
  150. this.$u.toast("请输入验证码");
  151. return;
  152. }
  153. if (!this.form.pwd) {
  154. this.$u.toast("请输入新密码");
  155. return;
  156. }
  157. if (!this.form.pwdAgain) {
  158. this.$u.toast("请输入确定新密码");
  159. return;
  160. }
  161. if (this.form.pwd != this.form.pwdAgain) {
  162. this.$u.toast("两次密码不一致");
  163. return;
  164. }
  165. that.isUse = true;
  166. let datas = {
  167. tel: this.form.tel,
  168. code: this.form.code,
  169. pwd: this.form.pwd,
  170. };
  171. that.$api.forgetUser(datas).then(
  172. (res) => {
  173. that.isUse = false;
  174. if (res.data.code == 200) {
  175. uni.showModal({
  176. title: "提示",
  177. content: "修改成功",
  178. showCancel: false,
  179. success: function (resst) {
  180. uni.navigateBack();
  181. },
  182. });
  183. } else {
  184. that.$u.toast(res.data.msg);
  185. }
  186. },
  187. (err) => {
  188. that.isUse = false;
  189. console.log(err);
  190. }
  191. );
  192. },
  193. codeChange(text) {
  194. this.codeTips = text;
  195. },
  196. // 获取验证码
  197. getCode() {
  198. let that = this;
  199. if (that.$refs.uCode.canGetCode) {
  200. if (that.$refs.tel.validateState == "success") {
  201. let datas = { tel: this.form.tel };
  202. that.$api.forgetSms(datas).then(
  203. (res) => {
  204. if (res.data.code == 200) {
  205. that.$u.toast("验证码已发送");
  206. // 通知验证码组件内部开始倒计时
  207. that.$refs.uCode.start();
  208. } else {
  209. that.$u.toast(res.data.msg);
  210. }
  211. },
  212. (err) => {
  213. console.log(err);
  214. }
  215. );
  216. } else {
  217. this.$refs.tel.onFieldChange();
  218. }
  219. }
  220. },
  221. },
  222. onLoad(option) {
  223. let that = this;
  224. // this.from = option.from; // 看页面没有用到
  225. uni.login({
  226. provider: "weixin",
  227. success: function (loginRes) {
  228. that.code = loginRes.code;
  229. },
  230. });
  231. },
  232. onReady() {
  233. this.$refs.uForm.setRules(this.rules);
  234. },
  235. };
  236. </script>
  237. <style scoped lang="scss">
  238. .wxBtn {
  239. position: fixed;
  240. bottom: 10%;
  241. width: 100%;
  242. left: 0;
  243. }
  244. /deep/ .wxBtn button::after {
  245. border: none;
  246. }
  247. .loginBtn {
  248. width: 526rpx;
  249. height: 80rpx;
  250. background: linear-gradient(90deg, #015eea, #00c0fa);
  251. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  252. opacity: 0.6;
  253. border-radius: 40rpx;
  254. color: #ffffff;
  255. text-align: center;
  256. line-height: 80rpx;
  257. margin: 40rpx auto;
  258. &.able {
  259. opacity: 1;
  260. }
  261. }
  262. .wxloginBtn {
  263. background: url("/static/loginBtn.png") no-repeat;
  264. background-size: 100% 100%;
  265. border: none;
  266. width: 100rpx;
  267. height: 100rpx;
  268. }
  269. /deep/page {
  270. background-color: #ffffff;
  271. height: 100%;
  272. width: 100%;
  273. }
  274. .login_box {
  275. width: 100%;
  276. height: 566rpx;
  277. background: #ffffff;
  278. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(1, 99, 235, 0.1);
  279. border-radius: 24rpx;
  280. margin-top: 30rpx;
  281. padding: 40rpx 35rpx;
  282. .password {
  283. /deep/.uicon-eye-fill {
  284. &::before {
  285. color: #007aff;
  286. content: "\e613";
  287. }
  288. }
  289. }
  290. }
  291. /deep/ .u-item-bg {
  292. border-radius: 32px !important;
  293. }
  294. /deep/ .u-subsection {
  295. border-radius: 32px !important;
  296. }
  297. .full_img {
  298. position: absolute;
  299. left: 0;
  300. display: block;
  301. width: 100%;
  302. z-index: -999;
  303. top: 0;
  304. }
  305. .head {
  306. height: 96rpx;
  307. width: 100%;
  308. line-height: 96rpx;
  309. margin-top: 40rpx;
  310. text-align: center;
  311. display: flex;
  312. position: relative;
  313. justify-content: center;
  314. }
  315. .icon {
  316. position: absolute;
  317. left: 30rpx;
  318. }
  319. .aa {
  320. padding: 10rpx;
  321. text-align: center;
  322. margin-top: 10rpx;
  323. }
  324. </style>