forget.vue 5.8 KB

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