login.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="wrap">
  3. <view class="login">
  4. <view class="login-title">
  5. <h3>手机号登录/注册</h3>
  6. <p>欢迎来到{{projectName}}</p>
  7. </view>
  8. <view class="login-form">
  9. <view class="login-form-item">
  10. <view class="title">手机号</view>
  11. <view class="input">
  12. <u-input v-model="form.telephone" type="number" placeholder="请输入手机号" placeholder-style="font-size:16px;color:#ccc;"/>
  13. </view>
  14. <view class="tips">未注册的手机号验证后将自动注册</view>
  15. </view>
  16. <view class="login-form-item">
  17. <view class="title">验证码</view>
  18. <view class="input">
  19. <u-input v-model="form.verifyCode" type="number" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
  20. <view class="code" @click="getCode">{{codeTips}}</view>
  21. </view>
  22. <view style="width: 350px;">
  23. <u-checkbox-group>
  24. <u-checkbox class="tips" active-color="green" v-model="value" shape="circle" @change="checkboxChange()"></u-checkbox>
  25. </u-checkbox-group>
  26. <span>我已阅读并同意</span>
  27. <span @click="gotoUrl('pages/article/details?code=YHXY')" style="color: #3fbd70;">《会员协议》</span>和
  28. <span @click="gotoUrl('pages/article/details?code=YSZC')" style="color: #3fbd70;">《隐私协议》</span>
  29. </view>
  30. </view>
  31. </view>
  32. <u-button :style="[inputStyle]" class="login-btn" type="success" shape="circle" @click="login">登录</u-button>
  33. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(Xs)">
  34. </u-verification-code>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import * as loginApi from '@/apis/login.js'
  40. import * as API from '@/apis/index.js'
  41. import {
  42. checkPhone
  43. } from '@/utils'
  44. export default {
  45. data() {
  46. return {
  47. form: {
  48. telephone: '',
  49. verifyCode: '',
  50. },
  51. isSendMsgIng: false,
  52. sendMsgSecond: 60,
  53. codeTips: '',
  54. value: false,
  55. code: '',
  56. codeId: '',
  57. projectName:'',
  58. }
  59. },
  60. computed: {
  61. inputStyle() {
  62. let style = {};
  63. if(this.form.telephone) {
  64. style.color = "#fff";
  65. style.backgroundColor = this.$u.color['success'];
  66. }
  67. return style;
  68. }
  69. },
  70. onLoad(op) {
  71. this.projectName=process.car.ProjectName;
  72. if(op.jpcode) {
  73. var str1 = op.jpcode.slice(0,19);
  74. var str2 = op.jpcode.slice(20,21);
  75. var str3 = op.jpcode.slice(22);
  76. if(str1 == 'jp_team51_charge_id') {
  77. if(str2 == 'A') {
  78. this.code = str2;
  79. this.codeId = str3;
  80. }
  81. }
  82. }
  83. },
  84. methods: {
  85. codeChange(text) {
  86. this.codeTips = text;
  87. },
  88. start() {
  89. if (!this.isSendMsgIng) {
  90. uni.showLoading({
  91. title: "加载中",
  92. mask: true,
  93. })
  94. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  95. uni.hideLoading();
  96. this.carhelp.set("getvcodetime", new Date().getTime());
  97. if (!"") {
  98. //倒计时
  99. uni.showToast({
  100. title: "发送成功"
  101. })
  102. } else {
  103. uni.showToast({
  104. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  105. })
  106. }
  107. }).catch(error => {
  108. uni.showToast({
  109. title: error,
  110. icon: "none"
  111. })
  112. })
  113. }
  114. },
  115. //倒计时
  116. end() {
  117. this.sendMsgSecond = 60;
  118. this.isSendMsgIng = false;
  119. },
  120. // 获取验证码
  121. getCode() {
  122. if (this.$refs.uCode.canGetCode) {} else {
  123. uni.showToast({
  124. title: '倒计时结束后再发送',
  125. icon: "none"
  126. })
  127. return
  128. }
  129. var checkPhoneResult = checkPhone(this.form.telephone);
  130. if (checkPhoneResult !== true) {
  131. uni.showToast({
  132. title: checkPhoneResult,
  133. })
  134. return;
  135. }
  136. this.$refs.uCode.start();
  137. },
  138. checkboxChange() {
  139. this.value = !this.value;
  140. },
  141. login() {
  142. var checkPhoneResult = checkPhone(this.form.telephone);
  143. if(!this.form.telephone || checkPhoneResult != true) {
  144. uni.showToast({
  145. title: checkPhoneResult,
  146. icon: "none"
  147. })
  148. return;
  149. }
  150. if(!this.form.verifyCode) {
  151. uni.showToast({
  152. title: "请输入验证码",
  153. icon: "none"
  154. })
  155. return
  156. }
  157. if(!this.value) {
  158. uni.showToast({
  159. title: "请勾选协议",
  160. icon: "none"
  161. })
  162. return
  163. }
  164. uni.showLoading({
  165. title: "加载中",
  166. mask: true,
  167. })
  168. loginApi.validateCode({
  169. verifyCode: this.form.verifyCode,
  170. telephone: this.form.telephone,
  171. nickName: this.carhelp.getUserInfo().nickname,
  172. openId: this.carhelp.getOpenId(),
  173. }).then((response) => {
  174. uni.hideLoading();
  175. var token = response ? response.data.token : '';
  176. this.carhelp.setToken(token);
  177. this.carhelp.setPersonInfo(response.data.regUser);
  178. if(this.code == 'A') {
  179. var k=API.codeOperation("jp_team51_charge_id:A_"+this.codeId);
  180. if(k){
  181. uni.redirectTo({
  182. url:k
  183. })
  184. }
  185. } else {
  186. uni.redirectTo({
  187. url: '/pages/index/index'
  188. })
  189. }
  190. }).catch(error => {
  191. uni.showToast({
  192. title: error,
  193. icon: "none"
  194. })
  195. })
  196. }
  197. }
  198. }
  199. </script>
  200. <style>
  201. page{
  202. background-color: #fff;
  203. }
  204. </style>
  205. <style lang="scss" scoped>
  206. .wrap {
  207. font-size: 28rpx;
  208. .login {
  209. width: 600rpx;
  210. padding-top: 80rpx;
  211. margin: 0 auto;
  212. .login-title {
  213. text-align: left;
  214. h3{
  215. font-size: 48rpx;
  216. font-weight: normal;
  217. }
  218. p{
  219. margin-top: 4px;
  220. color:#777
  221. }
  222. }
  223. .login-form-item{
  224. margin-top: 40px;
  225. .title{
  226. margin-bottom: 8px;
  227. }
  228. .input {
  229. border-bottom: 1px solid #f7f7f7;
  230. position: relative;
  231. }
  232. .code{
  233. position: absolute;
  234. right: 0;
  235. top:7px;
  236. color:#1677FF;
  237. }
  238. .tips {
  239. color: $u-type-info;
  240. margin-top: 12px;
  241. font-size: 12px;
  242. span{
  243. color:#3fbd70;
  244. }
  245. }
  246. }
  247. .login-btn {
  248. margin-top: 40px;
  249. background-color: #a7dbc2;
  250. }
  251. .alternative {
  252. color: $u-tips-color;
  253. display: flex;
  254. justify-content: space-between;
  255. margin-top: 30rpx;
  256. }
  257. }
  258. }
  259. </style>