register.vue 7.6 KB

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