codeLogin.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <!-- 验证码登录 -->
  3. <view>
  4. <u-navbar title="" autoBack placeholder></u-navbar>
  5. <view class="card_login">
  6. <view class="card_head_logo">
  7. <image class="mine_image" src="../static/logo.png" mode=""></image>
  8. <view class="welcome_title">欢迎登录宝智达冷链运输</view>
  9. </view>
  10. <u-form labelPosition="left" :model="formList" :rules="rules" ref="uForm">
  11. <u-form-item label="手机号" prop="phone" labelWidth="80" borderBottom ref="item1">
  12. <u-input v-model="formList.phone" border="none" placeholder="请填写手机号"></u-input>
  13. </u-form-item>
  14. <u-form-item label="验证码" prop="verifyCode" labelWidth="80" borderBottom>
  15. <u-input v-model="formList.verifyCode" border="none" placeholder="请填写验证码"></u-input>
  16. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="mini"
  17. :disabled="disabled1"></u-button>
  18. </u-form-item>
  19. </u-form>
  20. <u-code ref="uCode" @change="codeChange" seconds="90" @start="disabled1 = true"
  21. @end="disabled1 = false"></u-code>
  22. <view class="btn_login">
  23. <view class="title_register" @click="posswordLogin">密码登录</view>
  24. <view class="title_register" @click="goRegister">去注册</view>
  25. </view>
  26. <view class="card_hint">
  27. <view class="card_checkbox">
  28. <u-checkbox-group @change="checkboxChange">
  29. <u-checkbox name="asgas" shape="circle"></u-checkbox>
  30. </u-checkbox-group>
  31. <span class="message" :style="{display:hintShow ? 'block' : 'none'}">
  32. 请先阅读并同意协议
  33. </span>
  34. </view>
  35. <view class="agreement_title">我已阅读并同意<span class="protocol_title">《用户协议》</span>、<span
  36. class="protocol_title">《隐私政策》</span>,
  37. 并授权宝智达气瓶使用该宝智达气瓶账号信息(如昵称、头像、收货地址)进行统一管理
  38. </view>
  39. </view>
  40. <view class="card_btn">
  41. <u-button type="primary" :disabled="disabled" text="登录" @click="getLogin"></u-button>
  42. </view>
  43. </view>
  44. <!-- <view class="wx_card">
  45. <view class="card_btn_wx frame">
  46. <u-icon name="weixin-fill" size="26" color="#07c160"></u-icon>
  47. </view>
  48. <span class="title_login_wx">微信登录</span>
  49. </view> -->
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. formList: {
  57. phone: '',
  58. verifyCode: '',
  59. },
  60. checked: false,
  61. hintShow: false,
  62. userInfo: {},
  63. tips: '',
  64. disabled1: false,
  65. rules: {
  66. phone: {
  67. type: 'string',
  68. required: true,
  69. message: '请填写手机号',
  70. trigger: ['blur']
  71. },
  72. verifyCode: {
  73. type: 'string',
  74. required: true,
  75. message: '请填写验证码',
  76. trigger: ['blur']
  77. },
  78. },
  79. }
  80. },
  81. computed: {
  82. disabled() {
  83. if (this.formList.phone == '' || this.formList.verifyCode == '') {
  84. return true;
  85. } else {
  86. return false;
  87. }
  88. }
  89. },
  90. // beforeCreate() {
  91. // var token = this.$cache.getToken()
  92. // if (token) {
  93. // uni.redirectTo({
  94. // url: '/pages/indexRouter'
  95. // })
  96. // }
  97. // },
  98. methods: {
  99. checkboxChange() {
  100. if (this.checked) {
  101. this.checked = false
  102. } else {
  103. this.checked = true
  104. this.hintShow = false
  105. }
  106. },
  107. getLogin() {
  108. if (!this.checked) {
  109. this.hintShow = true
  110. } else {
  111. uni.showLoading({
  112. title: '登录中...'
  113. });
  114. this.$api.post('/api/applet/login', {
  115. phone: this.formList.phone,
  116. verifyCode: this.formList.verifyCode
  117. }).then((res) => {
  118. console.log(res,4443)
  119. if (res.code == 200) {
  120. this.$cache.setToken(res.data.token)
  121. // this.getUserInfo()
  122. uni.redirectTo({
  123. url: '/pages/indexRouter'
  124. })
  125. } else {
  126. uni.showToast({
  127. title: res.msg,
  128. icon: 'none'
  129. });
  130. }
  131. uni.hideLoading();
  132. })
  133. }
  134. },
  135. getUserInfo() {
  136. this.$api.get('/api/user/profile').then(res => {
  137. if (res.code == 200) {
  138. this.userInfo = res.data
  139. this.$cache.setCache('userInfo', this.userInfo)
  140. uni.redirectTo({
  141. url: '/pages/indexRouter'
  142. })
  143. } else {
  144. uni.showToast({
  145. title: '当前用户不存在',
  146. icon: 'none'
  147. });
  148. }
  149. })
  150. },
  151. getCode() {
  152. if (this.$refs.uCode.canGetCode) {
  153. // 模拟向后端请求验证码
  154. if (this.formList.phone) {
  155. uni.showLoading({
  156. title: '正在获取验证码'
  157. })
  158. // 通知验证码组件内部开始倒计时
  159. this.$refs.uCode.start();
  160. this.$api.get('/api/verify-code', {
  161. phone: this.formList.phone,
  162. }).then(res => {
  163. if (res.code == 200) {
  164. // 这里此提示会被this.start()方法中的提示覆盖
  165. uni.$u.toast('验证码已发送');
  166. }
  167. uni.hideLoading();
  168. })
  169. } else {
  170. uni.$u.toast('请先输入手机号');
  171. }
  172. } else {
  173. uni.$u.toast('倒计时结束后再发送');
  174. }
  175. },
  176. codeChange(text) {
  177. this.tips = text;
  178. },
  179. // 密码登录
  180. posswordLogin() {
  181. uni.redirectTo({
  182. url: '/pages/login'
  183. })
  184. },
  185. // 注册
  186. goRegister() {
  187. uni.navigateTo({
  188. url: '/pages/register'
  189. })
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss">
  195. page {
  196. background-color: #fff !important;
  197. }
  198. .welcome_title {
  199. font-size: 46rpx;
  200. font-weight: 600;
  201. margin-bottom: 60rpx;
  202. margin-top: 10rpx;
  203. }
  204. .card_head_logo {
  205. margin-top: 50rpx;
  206. display: flex;
  207. flex-direction: column;
  208. justify-content: center;
  209. align-items: center;
  210. }
  211. .card_login {
  212. padding: 20rpx 40rpx;
  213. }
  214. .mine_image {
  215. width: 100rpx;
  216. height: 100rpx;
  217. }
  218. .login_input_box {
  219. margin-bottom: 30rpx;
  220. }
  221. .title_register {
  222. display: flex;
  223. justify-content: flex-end;
  224. font-size: 28rpx;
  225. color: #494949;
  226. }
  227. .card_hint {
  228. margin-top: 60rpx;
  229. display: flex;
  230. align-items: flex-start;
  231. }
  232. .agreement_title {
  233. font-size: 26rpx;
  234. color: #333;
  235. }
  236. .protocol_title {
  237. color: #1177ff;
  238. }
  239. .card_btn {
  240. margin-top: 20rpx;
  241. }
  242. .card_checkbox {
  243. margin-top: 5rpx;
  244. position: relative;
  245. cursor: pointer;
  246. }
  247. .message {
  248. display: none;
  249. position: absolute;
  250. padding: 5px 8px;
  251. border: 1px solid #494949;
  252. border-radius: 9px;
  253. top: -36px;
  254. font-size: 12px;
  255. width: 110px;
  256. background: #494949;
  257. color: #fff;
  258. left: -6px;
  259. }
  260. .message::after {
  261. content: '';
  262. position: absolute;
  263. left: 8px;
  264. top: 100%;
  265. border: 8px solid transparent;
  266. border-top: 6px solid #494949;
  267. margin-left: -2px;
  268. }
  269. .btn_login {
  270. margin-top: 20rpx;
  271. display: flex;
  272. justify-content: space-between;
  273. }
  274. </style>