register.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="content">
  3. <view class="form vflex">
  4. <u-input v-model="userInfo.name" placeholder="请输入昵称"></u-input>
  5. <u-input v-model="userInfo.phone" placeholder="请输入手机号码"></u-input>
  6. <u-input v-model="userInfo.code" placeholder="请输入验证码">
  7. <template slot="suffix">
  8. <u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
  9. <view class="code" @tap="getCode">{{tips}}</view>
  10. </template>
  11. </u-input>
  12. <u-input :type="pwd_type" v-model="userInfo.password" placeholder="请输入密码">
  13. <template slot="suffix">
  14. <view @click="show_pwd" v-if="pwd_type == 'password'">
  15. <image src="/static/images/login/biyanjing.png" class="pwd_icon"></image>
  16. </view>
  17. <view @click="show_pwd" v-if="pwd_type == 'text'">
  18. <image src="/static/images/login/yanjing.png" class="pwd_icon"></image>
  19. </view>
  20. </template>
  21. </u-input>
  22. </view>
  23. <view class="hflex acenter">
  24. <u-checkbox-group @change="checkboxChange">
  25. <u-checkbox v-model="agree" shape="circle"></u-checkbox>
  26. </u-checkbox-group>
  27. <view class="text">阅读并同意<span class="read" @click="open(0)">《用户服务协议》</span>、<span class="read" @click="open(1)">《个人信息保护政策》</span></view>
  28. </view>
  29. <view class="button hflex acenter jcenter" @click="submit">
  30. <view>注册</view>
  31. </view>
  32. <!-- 弹出层 -->
  33. <u-modal :show="showProtocol" :title="protocolTitle" confirmColor="#2988FE" @confirm="isRead" confirmText="我已阅读">
  34. <view class="slot-content">
  35. <rich-text :nodes="protocolContent"></rich-text>
  36. </view>
  37. </u-modal>
  38. </view>
  39. </template>
  40. <script>
  41. import $api from '@/static/js/api.js'
  42. var that = ''
  43. export default {
  44. data() {
  45. return {
  46. userInfo: {
  47. name: '',
  48. phone: '',
  49. password: '',
  50. code: '',
  51. },
  52. tips: '',
  53. agree: false,
  54. pwd_type: 'password',
  55. show: false,
  56. showProtocol: false,
  57. protocolTitle: '',
  58. protocolContent: '',
  59. }
  60. },
  61. onLoad() {
  62. that = this
  63. },
  64. watch: {
  65. value(newValue,oldValue) {
  66. }
  67. },
  68. methods: {
  69. // 查看密码
  70. show_pwd() {
  71. if(that.pwd_type == 'text') {
  72. that.pwd_type = 'password'
  73. } else {
  74. that.pwd_type = 'text'
  75. }
  76. },
  77. // 验证码文字
  78. codeChange(text) {
  79. that.tips = text
  80. },
  81. // 获取验证码
  82. getCode() {
  83. if(that.$refs.uCode.canGetCode) {
  84. uni.showLoading({
  85. title: '正在获取验证码'
  86. })
  87. $api.req({
  88. url: '/data/api.Login/sendsms',
  89. method: 'POST',
  90. data: {
  91. phone: that.userInfo.phone,
  92. type: 2
  93. }
  94. }, function(res) {
  95. uni.hideLoading();
  96. if(res.code == 1) {
  97. uni.$u.toast('验证码已发送')
  98. that.$refs.uCode.start()
  99. } else {
  100. uni.$u.toast('验证码发送失败')
  101. }
  102. })
  103. } else {
  104. uni.$u.toast('倒计时结束后再发送')
  105. }
  106. },
  107. // 阅读并同意
  108. checkboxChange(n) {
  109. this.agree = !this.agree
  110. },
  111. open(index) {
  112. const that = this
  113. $api.req({
  114. url: '/data/api.Login/getloginset'
  115. }, function(res) {
  116. if (res.code == 1) {
  117. if(index == 0) {
  118. uni.setStorageSync('xieyi',res.data.service_agreement)
  119. $api.jump('/pages/user/agreement?title=用户服务协议')
  120. } else {
  121. uni.setStorageSync('xieyi',res.data.protection_policy)
  122. $api.jump('/pages/user/agreement?title=个人隐私保护政策')
  123. }
  124. }
  125. })
  126. },
  127. isRead() {
  128. that.showProtocol = false
  129. },
  130. // 提交
  131. submit() {
  132. if ($api.formCheck(that.userInfo.name,"required") && $api.formCheck(that.userInfo.phone,"phone") && $api.formCheck(that.userInfo.code, "code6") && $api.formCheck(that.userInfo.password,"password")) {
  133. if (!that.agree) {
  134. $api.info('请先阅读并同意用户协议和隐私协议')
  135. } else {
  136. $api.req({
  137. url: '/data/api.Login/register',
  138. method: 'POST',
  139. data: {
  140. nickname: that.userInfo.name,
  141. phone: that.userInfo.phone,
  142. verify: that.userInfo.code,
  143. password: that.userInfo.password,
  144. }
  145. }, function(res) {
  146. console.log(res)
  147. if(res.code == 1) {
  148. wx.setStorageSync("token",res.data.token)
  149. wx.setStorageSync("id",res.data.id)
  150. $api.jump('/pages/tabbar/mine/mine',3)
  151. // uni.WebIM.conn.registerUser({
  152. // /** 用户 ID。 */
  153. // username: res.data.id,
  154. // /** 密码。 */
  155. // password: '123456',
  156. // /** 显示昵称。用于移动端推送的时候通知栏显示。 */
  157. // nickname:res.data.nickname,
  158. // appKey: uni.WebIM.config.appkey
  159. // }).then((res2) => {
  160. // console.log(res2)
  161. // $api.jump('/pages/tabbar/mine/mine',3)
  162. // })
  163. }
  164. })
  165. // wx.setStorageSync("token",true)
  166. // $api.jump('/pages/tabbar/mine/mine',3)
  167. }
  168. }
  169. }
  170. },
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .content::v-deep {
  175. padding: 0 60rpx;
  176. .form {
  177. width: 100%;
  178. padding-top: 64rpx;
  179. .u-input {
  180. width: 630rpx !important;
  181. height: 104rpx !important;
  182. background-color: #f4f4f4;
  183. border-radius: 52rpx;
  184. font-size: 30rpx !important;
  185. box-sizing: border-box;
  186. padding: 30rpx 48rpx !important;
  187. margin: 26rpx 0;
  188. }
  189. .pwd_icon {
  190. width: 40rpx;
  191. height: 40rpx;
  192. }
  193. .code {
  194. font-size: 30rpx;
  195. color: #506dff;
  196. }
  197. }
  198. .text {
  199. font-size: 24rpx;
  200. color: #9c9c9c;
  201. }
  202. .read {
  203. color: #2a63f3;
  204. }
  205. .button {
  206. width: 100%;
  207. height: 96rpx;
  208. background-color: #506dff;
  209. border-radius: 50rpx;
  210. box-shadow: 0 4rpx 28rpx 0 rgba(132,123,255,0.4);
  211. font-size: 40rpx;
  212. color: #fff;
  213. margin: 40rpx 0 36rpx;
  214. }
  215. }
  216. </style>