forget.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. mounted() {},
  132. methods: {
  133. canSubmit() {
  134. if (
  135. this.form.tel &&
  136. this.form.code &&
  137. this.form.pwd &&
  138. this.form.pwdAgain
  139. ) {
  140. return true;
  141. }
  142. return false;
  143. },
  144. submit() {
  145. let that = this;
  146. if (!this.form.tel) {
  147. this.$u.toast("请输入手机号码");
  148. return;
  149. }
  150. if (!this.form.code) {
  151. this.$u.toast("请输入验证码");
  152. return;
  153. }
  154. if (!this.form.pwd) {
  155. this.$u.toast("请输入新密码");
  156. return;
  157. }
  158. if (!this.form.pwdAgain) {
  159. this.$u.toast("请输入确定新密码");
  160. return;
  161. }
  162. if (this.form.pwd != this.form.pwdAgain) {
  163. this.$u.toast("两次密码不一致");
  164. return;
  165. }
  166. that.isUse = true;
  167. let datas = {
  168. tel: this.form.tel,
  169. code: this.form.code,
  170. pwd: this.form.pwd,
  171. };
  172. that.$api.forgetUser(datas).then(
  173. (res) => {
  174. that.isUse = false;
  175. if (res.data.code == 200) {
  176. uni.showModal({
  177. title: "提示",
  178. content: "修改成功",
  179. showCancel: false,
  180. success: function (resst) {
  181. uni.navigateBack();
  182. },
  183. });
  184. } else {
  185. that.$u.toast(res.data.msg);
  186. }
  187. },
  188. (err) => {
  189. that.isUse = false;
  190. console.log(err);
  191. }
  192. );
  193. },
  194. radioGroupChange(e) {
  195. console.log(e);
  196. },
  197. codeChange(text) {
  198. this.codeTips = text;
  199. },
  200. // 获取验证码
  201. getCode() {
  202. let that = this;
  203. if (that.$refs.uCode.canGetCode) {
  204. if (that.$refs.tel.validateState == "success") {
  205. let datas = { tel: this.form.tel };
  206. that.$api.forgetSms(datas).then(
  207. (res) => {
  208. if (res.data.code == 200) {
  209. that.$u.toast("验证码已发送");
  210. // 通知验证码组件内部开始倒计时
  211. that.$refs.uCode.start();
  212. } else {
  213. that.$u.toast(res.data.msg);
  214. }
  215. },
  216. (err) => {
  217. console.log(err);
  218. }
  219. );
  220. } else {
  221. this.$refs.tel.onFieldChange();
  222. }
  223. }
  224. },
  225. sectionChange(index) {
  226. this.current = index;
  227. },
  228. getPhoneNumber(e) {
  229. let that = this;
  230. uni.checkSession({
  231. success() {
  232. //session_key 未过期,并且在本生命周期一直有效
  233. that.putInfo(e);
  234. },
  235. fail() {
  236. // session_key 已经失效,需要重新执行登录流程
  237. uni.login({
  238. provider: "weixin",
  239. success: function (loginRes) {
  240. that.code = loginRes.code;
  241. that.putInfo(e);
  242. },
  243. });
  244. },
  245. });
  246. },
  247. putInfo(e) {
  248. let that = this;
  249. if (e.detail.encryptedData) {
  250. let inviteCode = uni.getStorageSync("inviteCode");
  251. //用户同意授权
  252. var datas = {
  253. iv: e.detail.iv,
  254. encryptedData: e.detail.encryptedData,
  255. code: that.code,
  256. };
  257. if (inviteCode) {
  258. datas.inviteCode = inviteCode;
  259. }
  260. that.$api.login(datas).then(
  261. (res) => {
  262. if (res.data.code == 200) {
  263. uni.setStorageSync("union_id", res.data.data.union_id);
  264. uni.setStorageSync("token", res.data.data.token);
  265. that.$api.getInfo().then((resdata) => {
  266. if (resdata.data.code == 200) {
  267. uni.navigateBack();
  268. that.$store.state.userInfo = resdata.data.data;
  269. }
  270. });
  271. } else {
  272. uni.showModal({
  273. title: "提示",
  274. content: res.data.msg,
  275. showCancel: false,
  276. });
  277. }
  278. },
  279. (err) => {
  280. console.log(err);
  281. }
  282. );
  283. }
  284. },
  285. },
  286. onLoad(option) {
  287. this.$refs.uForm.setRules(this.rules);
  288. let that = this;
  289. this.from = option.from;
  290. uni.login({
  291. provider: "weixin",
  292. success: function (loginRes) {
  293. that.code = loginRes.code;
  294. },
  295. });
  296. },
  297. };
  298. </script>
  299. <style scoped lang="scss">
  300. .wxBtn {
  301. position: fixed;
  302. bottom: 10%;
  303. width: 100%;
  304. left: 0;
  305. }
  306. /deep/ .wxBtn button::after {
  307. border: none;
  308. }
  309. .loginBtn {
  310. width: 526rpx;
  311. height: 80rpx;
  312. background: linear-gradient(90deg, #015eea, #00c0fa);
  313. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  314. opacity: 0.6;
  315. border-radius: 40rpx;
  316. color: #ffffff;
  317. text-align: center;
  318. line-height: 80rpx;
  319. margin: 40rpx auto;
  320. &.able {
  321. opacity: 1;
  322. }
  323. }
  324. .wxloginBtn {
  325. background: url("/static/loginBtn.png") no-repeat;
  326. background-size: 100% 100%;
  327. border: none;
  328. width: 100rpx;
  329. height: 100rpx;
  330. }
  331. /deep/page {
  332. background-color: #ffffff;
  333. height: 100%;
  334. width: 100%;
  335. }
  336. .login_box {
  337. width: 100%;
  338. height: 566rpx;
  339. background: #ffffff;
  340. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(1, 99, 235, 0.1);
  341. border-radius: 24rpx;
  342. margin-top: 30rpx;
  343. padding: 40rpx 35rpx;
  344. .password {
  345. /deep/.uicon-eye-fill {
  346. &::before {
  347. color: #007aff;
  348. content: "\e613";
  349. }
  350. }
  351. }
  352. }
  353. /deep/ .u-item-bg {
  354. border-radius: 32px !important;
  355. }
  356. /deep/ .u-subsection {
  357. border-radius: 32px !important;
  358. }
  359. .full_img {
  360. position: absolute;
  361. left: 0;
  362. display: block;
  363. width: 100%;
  364. z-index: -999;
  365. top: 0;
  366. }
  367. .head {
  368. height: 96rpx;
  369. width: 100%;
  370. line-height: 96rpx;
  371. margin-top: 40rpx;
  372. text-align: center;
  373. display: flex;
  374. position: relative;
  375. justify-content: center;
  376. }
  377. .icon {
  378. position: absolute;
  379. left: 30rpx;
  380. }
  381. </style>