forget.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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="getCodepre">{{
  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. <u-popup v-model="codeModal" :mask-close-able="false" closeable mode="center" width="80%" border-radius="24">
  70. <view class="rf-popup-main">
  71. <view class="title">获取手机验证码</view>
  72. <u-form >
  73. <u-form-item prop="imageCode">
  74. <u-input v-model="imageCode" type="number" placeholder-style="color:#999999"
  75. placeholder="图形验证码" />
  76. <image slot="right" style="width: 212rpx;height: 80rpx;margin-bottom: 40rpx;" :src="codeUrl" @click="getCodepre"></image>
  77. </u-form-item>
  78. </u-form>
  79. <u-button type="primary" style="border-radius: 60rpx;" @click="getCode">获取手机验证码</u-button>
  80. </view>
  81. </u-popup>
  82. </view>
  83. </template>
  84. <script>
  85. export default {
  86. data() {
  87. return {
  88. code: "",
  89. codeModal: false,
  90. imageCode:"",
  91. imageUuid:"",
  92. codeUrl:"",
  93. form: {
  94. code: "",
  95. tel: "",
  96. pwd: "",
  97. pwdAgain: "",
  98. },
  99. rules: {
  100. tel: [
  101. {
  102. required: true,
  103. message: "请输入手机号",
  104. // 可以单个或者同时写两个触发验证方式
  105. trigger: ["change"],
  106. },
  107. {
  108. validator: (rule, value, callback) => {
  109. // 上面有说,返回true表示校验通过,返回false表示不通过
  110. // this.$u.test.mobile()就是返回true或者false的
  111. return this.$u.test.mobile(value);
  112. },
  113. message: "手机号码格式不正确",
  114. // 触发器可以同时用blur和change
  115. trigger: ["change"],
  116. },
  117. ],
  118. pwd: [
  119. {
  120. required: true,
  121. message: "请输入密码",
  122. // 可以单个或者同时写两个触发验证方式
  123. trigger: ["change"],
  124. },
  125. ],
  126. pwdAgain: [
  127. {
  128. required: true,
  129. message: "请输入密码",
  130. // 可以单个或者同时写两个触发验证方式
  131. trigger: ["change"],
  132. },
  133. ],
  134. code: [
  135. {
  136. required: true,
  137. message: "请输入验证码",
  138. // 可以单个或者同时写两个触发验证方式
  139. trigger: ["change"],
  140. },
  141. ],
  142. },
  143. codeTips: "",
  144. read: "",
  145. isUse: false,
  146. };
  147. },
  148. methods: {
  149. canSubmit() {
  150. if (
  151. this.form.tel &&
  152. this.form.code &&
  153. this.form.pwd &&
  154. this.form.pwdAgain
  155. ) {
  156. return true;
  157. }
  158. return false;
  159. },
  160. submit() {
  161. let that = this;
  162. if (!this.form.tel) {
  163. this.$u.toast("请输入手机号码");
  164. return;
  165. }
  166. if (!this.form.code) {
  167. this.$u.toast("请输入验证码");
  168. return;
  169. }
  170. if (!this.form.pwd) {
  171. this.$u.toast("请输入新密码");
  172. return;
  173. }
  174. if (!this.form.pwdAgain) {
  175. this.$u.toast("请输入确定新密码");
  176. return;
  177. }
  178. if (this.form.pwd != this.form.pwdAgain) {
  179. this.$u.toast("两次密码不一致");
  180. return;
  181. }
  182. that.isUse = true;
  183. let datas = {
  184. tel: this.form.tel,
  185. code: this.form.code,
  186. pwd: this.form.pwd,
  187. };
  188. that.$api.forgetUser(datas).then(
  189. (res) => {
  190. that.isUse = false;
  191. if (res.data.code == 200) {
  192. uni.showModal({
  193. title: "提示",
  194. content: "修改成功",
  195. showCancel: false,
  196. success: function (resst) {
  197. uni.navigateBack();
  198. },
  199. });
  200. } else {
  201. that.$u.toast(res.data.msg);
  202. }
  203. },
  204. (err) => {
  205. that.isUse = false;
  206. console.log(err);
  207. }
  208. );
  209. },
  210. codeChange(text) {
  211. this.codeTips = text;
  212. },
  213. //获取图形验证码
  214. getCodepre(){
  215. this.codeModal=true;
  216. this.$api.captchaImage({}).then(
  217. (res) => {
  218. if (res.data.code == 200) {
  219. this.codeUrl = "data:image/gif;base64," + res.data.data.img;
  220. this.imageUuid= res.data.data.uuid;
  221. } else {
  222. this.$u.toast(res.data.msg);
  223. }
  224. },
  225. (err) => {
  226. console.log(err);
  227. }
  228. );
  229. },
  230. // 获取验证码
  231. getCode() {
  232. let that = this;
  233. if(!this.imageCode)
  234. {
  235. that.$u.toast("请输入图形验证码");
  236. return;
  237. }
  238. if (that.$refs.uCode.canGetCode) {
  239. if (that.$refs.tel.validateState == "success") {
  240. let datas = {
  241. tel: this.form.tel ,
  242. imageCode:this.imageCode,
  243. imageUuid:this.imageUuid,
  244. };
  245. that.$api.forgetSms(datas).then(
  246. (res) => {
  247. if (res.data.code == 200) {
  248. this.codeModal=false;
  249. that.$u.toast("验证码已发送");
  250. // 通知验证码组件内部开始倒计时
  251. that.$refs.uCode.start();
  252. } else {
  253. that.$u.toast(res.data.msg);
  254. }
  255. },
  256. (err) => {
  257. console.log(err);
  258. }
  259. );
  260. } else {
  261. this.$refs.tel.onFieldChange();
  262. }
  263. }
  264. },
  265. },
  266. onLoad(option) {
  267. let that = this;
  268. // this.from = option.from; // 看页面没有用到
  269. uni.login({
  270. provider: "weixin",
  271. success: function (loginRes) {
  272. that.code = loginRes.code;
  273. },
  274. });
  275. },
  276. onReady() {
  277. this.$refs.uForm.setRules(this.rules);
  278. },
  279. };
  280. </script>
  281. <style scoped lang="scss">
  282. .wxBtn {
  283. position: fixed;
  284. bottom: 10%;
  285. width: 100%;
  286. left: 0;
  287. }
  288. /deep/ .wxBtn button::after {
  289. border: none;
  290. }
  291. .loginBtn {
  292. width: 526rpx;
  293. height: 80rpx;
  294. background: linear-gradient(90deg, #015eea, #00c0fa);
  295. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  296. opacity: 0.6;
  297. border-radius: 40rpx;
  298. color: #ffffff;
  299. text-align: center;
  300. line-height: 80rpx;
  301. margin: 40rpx auto;
  302. &.able {
  303. opacity: 1;
  304. }
  305. }
  306. .wxloginBtn {
  307. background: url("/static/loginBtn.png") no-repeat;
  308. background-size: 100% 100%;
  309. border: none;
  310. width: 100rpx;
  311. height: 100rpx;
  312. }
  313. /deep/page {
  314. background-color: #ffffff;
  315. height: 100%;
  316. width: 100%;
  317. }
  318. .login_box {
  319. width: 100%;
  320. height: 566rpx;
  321. background: #ffffff;
  322. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(1, 99, 235, 0.1);
  323. border-radius: 24rpx;
  324. margin-top: 30rpx;
  325. padding: 40rpx 35rpx;
  326. .password {
  327. /deep/.uicon-eye-fill {
  328. &::before {
  329. color: #007aff;
  330. content: "\e613";
  331. }
  332. }
  333. }
  334. }
  335. /deep/ .u-item-bg {
  336. border-radius: 32px !important;
  337. }
  338. /deep/ .u-subsection {
  339. border-radius: 32px !important;
  340. }
  341. .full_img {
  342. position: absolute;
  343. left: 0;
  344. display: block;
  345. width: 100%;
  346. z-index: -999;
  347. top: 0;
  348. }
  349. .head {
  350. height: 96rpx;
  351. width: 100%;
  352. line-height: 96rpx;
  353. margin-top: 40rpx;
  354. text-align: center;
  355. display: flex;
  356. position: relative;
  357. justify-content: center;
  358. }
  359. .icon {
  360. position: absolute;
  361. left: 30rpx;
  362. }
  363. .aa {
  364. padding: 10rpx;
  365. text-align: center;
  366. margin-top: 10rpx;
  367. }
  368. .rf-popup-main {
  369. text-align: center;
  370. padding: 40rpx;
  371. .title {
  372. font-size: 40rpx;
  373. font-weight: 600;
  374. }
  375. .tip {
  376. margin: 30rpx 0 40rpx;
  377. font-size: 32rpx;
  378. }
  379. .u-input {
  380. border-radius: 20rpx;
  381. background: #eee;
  382. padding-left: 20rpx !important;
  383. margin-bottom: 40rpx;
  384. }
  385. .u-button {
  386. border-radius: 60rpx !important;
  387. }
  388. }
  389. </style>