login.vue 6.0 KB

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