login.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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">欢迎登录宝智达冷链送药</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/indexRouter'
  123. })
  124. } else {
  125. uni.showToast({
  126. title: res.data.msg,
  127. icon: 'none'
  128. });
  129. }
  130. uni.hideLoading();
  131. }).catch(() => {
  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.user
  140. this.$cache.setCache('userInfo', this.userInfo)
  141. uni.redirectTo({
  142. url: '/pages/indexRouter'
  143. })
  144. } else {
  145. uni.showToast({
  146. title: '当前用户不存在',
  147. icon: 'none'
  148. });
  149. }
  150. })
  151. },
  152. // 验证码登录
  153. codeLogin() {
  154. uni.redirectTo({
  155. url: '/pages/codeLogin'
  156. })
  157. },
  158. // 注册
  159. goRegister() {
  160. this.$refs.uForm.resetFields()
  161. uni.navigateTo({
  162. url: '/pages/register'
  163. })
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss">
  169. page {
  170. background-color: #fff !important;
  171. }
  172. .welcome_title {
  173. font-size: 46rpx;
  174. font-weight: 600;
  175. margin-bottom: 60rpx;
  176. margin-top: 10rpx;
  177. }
  178. .card_head_logo {
  179. margin-top: 50rpx;
  180. display: flex;
  181. flex-direction: column;
  182. justify-content: center;
  183. align-items: center;
  184. }
  185. .card_login {
  186. padding: 20rpx 40rpx;
  187. }
  188. .mine_image {
  189. width: 100rpx;
  190. height: 100rpx;
  191. }
  192. .title_register {
  193. display: flex;
  194. justify-content: flex-end;
  195. font-size: 28rpx;
  196. color: #494949;
  197. }
  198. .card_hint {
  199. margin-top: 60rpx;
  200. display: flex;
  201. align-items: flex-start;
  202. }
  203. .agreement_title {
  204. font-size: 26rpx;
  205. color: #333;
  206. }
  207. .protocol_title {
  208. color: #1177ff;
  209. }
  210. .card_btn {
  211. margin-top: 20rpx;
  212. }
  213. .card_checkbox {
  214. margin-top: 5rpx;
  215. position: relative;
  216. cursor: pointer;
  217. }
  218. .message {
  219. display: none;
  220. position: absolute;
  221. padding: 5px 8px;
  222. border: 1px solid #494949;
  223. border-radius: 9px;
  224. top: -36px;
  225. font-size: 12px;
  226. width: 110px;
  227. background: #494949;
  228. color: #fff;
  229. left: -6px;
  230. }
  231. .message::after {
  232. content: '';
  233. position: absolute;
  234. left: 8px;
  235. top: 100%;
  236. border: 8px solid transparent;
  237. border-top: 6px solid #494949;
  238. margin-left: -2px;
  239. }
  240. .btn_login {
  241. margin-top: 20rpx;
  242. display: flex;
  243. justify-content: space-between;
  244. }
  245. </style>