forget.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view style="height: 100%;">
  3. <image mode="widthFix" src="/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 ><u-input v-model="form.tel" type="number" maxlength="11" placeholder="手机号"/></u-form-item>
  9. <u-form-item >
  10. <u-input v-model="form.code" type="number" placeholder="验证码"/>
  11. <u-button slot="right" size="mini" @click="getCode">{{codeTips}}</u-button>
  12. </u-form-item>
  13. <u-form-item ><u-input v-model="form.pwd" type="password" placeholder="请输入新密码"/></u-form-item>
  14. <u-form-item ><u-input 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. codeTips: '',
  36. read:'',
  37. isUse:false
  38. };
  39. },
  40. mounted() {},
  41. methods: {
  42. canSubmit() {
  43. if(this.form.tel && this.form.code && this.form.pwd && this.form.pwdAgain) {
  44. return true;
  45. }
  46. return false;
  47. },
  48. submit(){
  49. let that = this
  50. if(!this.form.tel){
  51. this.$u.toast('请输入手机号码');
  52. return
  53. }
  54. if(!this.form.code){
  55. this.$u.toast('请输入验证码');
  56. return
  57. }
  58. if(!this.form.pwd){
  59. this.$u.toast('请输入新密码');
  60. return
  61. }
  62. if(!this.form.pwdAgain){
  63. this.$u.toast('请输入确定新密码');
  64. return
  65. }
  66. if(this.form.pwd!=this.form.pwdAgain){
  67. this.$u.toast('两次密码不一致');
  68. return
  69. }
  70. that.isUse = true
  71. let datas = {
  72. tel:this.form.tel,
  73. code:this.form.code,
  74. pwd:this.form.pwd
  75. }
  76. that.$api.forgetUser(datas).then(
  77. res => {
  78. that.isUse = false
  79. if (res.data.code == 200) {
  80. uni.showModal({
  81. title: '提示',
  82. content: '修改成功',
  83. showCancel:false,
  84. success: function(resst) {
  85. uni.navigateBack()
  86. }
  87. });
  88. } else {
  89. that.$u.toast(res.data.msg);
  90. }
  91. },
  92. err => {
  93. that.isUse = false
  94. console.log(err);
  95. }
  96. );
  97. },
  98. radioGroupChange(e) {
  99. console.log(e);
  100. },
  101. codeChange(text) {
  102. this.codeTips = text;
  103. },
  104. // 获取验证码
  105. getCode() {
  106. let that = this
  107. if(that.$refs.uCode.canGetCode) {
  108. if(!this.form.tel){
  109. this.$u.toast('请输入手机号码');
  110. return
  111. }
  112. let datas = {tel:this.form.tel}
  113. that.$api.forgetSms(datas).then(
  114. res => {
  115. if (res.data.code == 200) {
  116. that.$u.toast('验证码已发送');
  117. // 通知验证码组件内部开始倒计时
  118. that.$refs.uCode.start();
  119. } else {
  120. that.$u.toast(res.data.msg);
  121. }
  122. },
  123. err => {
  124. console.log(err);
  125. }
  126. );}
  127. },
  128. sectionChange(index) {
  129. this.current = index;
  130. },
  131. getPhoneNumber(e) {
  132. let that = this;
  133. uni.checkSession({
  134. success () {
  135. //session_key 未过期,并且在本生命周期一直有效
  136. that.putInfo(e)
  137. },
  138. fail () {
  139. // session_key 已经失效,需要重新执行登录流程
  140. uni.login({
  141. provider: 'weixin',
  142. success: function(loginRes) {
  143. that.code = loginRes.code;
  144. that.putInfo(e)
  145. }
  146. });
  147. }
  148. })
  149. },
  150. putInfo(e){
  151. let that = this;
  152. if (e.detail.encryptedData) {
  153. let inviteCode = uni.getStorageSync("inviteCode")
  154. //用户同意授权
  155. var datas = {
  156. iv: e.detail.iv,
  157. encryptedData: e.detail.encryptedData,
  158. code: that.code
  159. };
  160. if(inviteCode){
  161. datas.inviteCode = inviteCode
  162. }
  163. that.$api.login(datas).then(
  164. res => {
  165. if (res.data.code == 200) {
  166. uni.setStorageSync('union_id', res.data.data.union_id);
  167. uni.setStorageSync('token', res.data.data.token);
  168. that.$api.getInfo().then(resdata => {
  169. if(resdata.data.code == 200){
  170. uni.navigateBack();
  171. that.$store.state.userInfo = resdata.data.data;
  172. }
  173. });
  174. } else {
  175. uni.showModal({
  176. title: '提示',
  177. content: res.data.msg,
  178. showCancel: false
  179. });
  180. }
  181. },
  182. err => {
  183. console.log(err);
  184. }
  185. );
  186. }
  187. }
  188. },
  189. onLoad(option) {
  190. let that = this;
  191. this.from = option.from;
  192. uni.login({
  193. provider: 'weixin',
  194. success: function(loginRes) {
  195. that.code = loginRes.code;
  196. }
  197. });
  198. }
  199. };
  200. </script>
  201. <style scoped lang="scss">
  202. .wxBtn{
  203. position: fixed;
  204. bottom: 10%;
  205. width: 100%;
  206. left: 0;
  207. }
  208. /deep/ .wxBtn button::after{
  209. border: none;
  210. }
  211. .loginBtn{
  212. width: 526rpx;
  213. height: 80rpx;
  214. background: linear-gradient(90deg, #015EEA, #00C0FA);
  215. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  216. opacity: 0.6;
  217. border-radius: 40rpx;
  218. color: #FFFFFF;
  219. text-align: center;
  220. line-height: 80rpx;
  221. margin: 40rpx auto;
  222. &.able {
  223. opacity: 1;
  224. }
  225. }
  226. .wxloginBtn{
  227. background: url("/static/loginBtn.png") no-repeat;
  228. background-size:100% 100%;
  229. border:none;
  230. width: 100rpx;
  231. height: 100rpx;
  232. }
  233. /deep/page {
  234. background-color: #FFFFFF;
  235. height: 100%;
  236. width: 100%;
  237. }
  238. .login_box{
  239. width: 100%;
  240. height: 566rpx;
  241. background: #FFFFFF;
  242. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(1, 99, 235, 0.1);
  243. border-radius: 24rpx;
  244. margin-top: 30rpx;
  245. padding:40rpx 35rpx;
  246. }
  247. /deep/ .u-item-bg{
  248. border-radius: 32px !important;
  249. }
  250. /deep/ .u-subsection{
  251. border-radius: 32px !important;
  252. }
  253. .full_img {
  254. position: absolute;
  255. left: 0;
  256. display: block;
  257. width: 100%;
  258. z-index: -999;
  259. top: 0;
  260. }
  261. .head {
  262. height: 96rpx;
  263. width: 100%;
  264. line-height: 96rpx;
  265. margin-top: 40rpx;
  266. text-align: center;
  267. display: flex;
  268. position: relative;
  269. justify-content: center;
  270. }
  271. .icon {
  272. position: absolute;
  273. left: 30rpx;
  274. }
  275. </style>