forget.vue 7.6 KB

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