codeLogin.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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/homePage'
  124. // url: '/pages/indexRouter'
  125. })
  126. } else {
  127. uni.showToast({
  128. title: res.msg,
  129. icon: 'none'
  130. });
  131. }
  132. uni.hideLoading();
  133. })
  134. }
  135. },
  136. getUserInfo() {
  137. this.$api.get('/api/user/profile').then(res => {
  138. if (res.code == 200) {
  139. this.userInfo = res.data
  140. this.$cache.setCache('userInfo', this.userInfo)
  141. uni.redirectTo({
  142. url: '/pages/homePage'
  143. // url: '/pages/indexRouter'
  144. })
  145. } else {
  146. uni.showToast({
  147. title: '当前用户不存在',
  148. icon: 'none'
  149. });
  150. }
  151. })
  152. },
  153. getCode() {
  154. if (this.$refs.uCode.canGetCode) {
  155. // 模拟向后端请求验证码
  156. if (this.formList.phone) {
  157. uni.showLoading({
  158. title: '正在获取验证码'
  159. })
  160. // 通知验证码组件内部开始倒计时
  161. this.$refs.uCode.start();
  162. this.$api.get('/api/verify-code', {
  163. phone: this.formList.phone,
  164. }).then(res => {
  165. if (res.code == 200) {
  166. // 这里此提示会被this.start()方法中的提示覆盖
  167. uni.$u.toast('验证码已发送');
  168. }
  169. uni.hideLoading();
  170. })
  171. } else {
  172. uni.$u.toast('请先输入手机号');
  173. }
  174. } else {
  175. uni.$u.toast('倒计时结束后再发送');
  176. }
  177. },
  178. codeChange(text) {
  179. this.tips = text;
  180. },
  181. // 密码登录
  182. posswordLogin() {
  183. uni.redirectTo({
  184. url: '/pages/login'
  185. })
  186. },
  187. // 注册
  188. goRegister() {
  189. uni.navigateTo({
  190. url: '/pages/register'
  191. })
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss">
  197. page {
  198. background-color: #fff !important;
  199. }
  200. .welcome_title {
  201. font-size: 46rpx;
  202. font-weight: 600;
  203. margin-bottom: 60rpx;
  204. margin-top: 10rpx;
  205. }
  206. .card_head_logo {
  207. margin-top: 50rpx;
  208. display: flex;
  209. flex-direction: column;
  210. justify-content: center;
  211. align-items: center;
  212. }
  213. .card_login {
  214. padding: 20rpx 40rpx;
  215. }
  216. .mine_image {
  217. width: 100rpx;
  218. height: 100rpx;
  219. }
  220. .login_input_box {
  221. margin-bottom: 30rpx;
  222. }
  223. .title_register {
  224. display: flex;
  225. justify-content: flex-end;
  226. font-size: 28rpx;
  227. color: #494949;
  228. }
  229. .card_hint {
  230. margin-top: 60rpx;
  231. display: flex;
  232. align-items: flex-start;
  233. }
  234. .agreement_title {
  235. font-size: 26rpx;
  236. color: #333;
  237. }
  238. .protocol_title {
  239. color: #1177ff;
  240. }
  241. .card_btn {
  242. margin-top: 20rpx;
  243. }
  244. .card_checkbox {
  245. margin-top: 5rpx;
  246. position: relative;
  247. cursor: pointer;
  248. }
  249. .message {
  250. display: none;
  251. position: absolute;
  252. padding: 5px 8px;
  253. border: 1px solid #494949;
  254. border-radius: 9px;
  255. top: -36px;
  256. font-size: 12px;
  257. width: 110px;
  258. background: #494949;
  259. color: #fff;
  260. left: -6px;
  261. }
  262. .message::after {
  263. content: '';
  264. position: absolute;
  265. left: 8px;
  266. top: 100%;
  267. border: 8px solid transparent;
  268. border-top: 6px solid #494949;
  269. margin-left: -2px;
  270. }
  271. .btn_login {
  272. margin-top: 20rpx;
  273. display: flex;
  274. justify-content: space-between;
  275. }
  276. </style>