login.vue 6.0 KB

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