login.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <!-- 蓝色登录页面2 -->
  2. <view>11111</view>
  3. <template>
  4. <view>
  5. <view class="img-a">
  6. <view class="t-b">
  7. 您好,
  8. <br />
  9. 欢迎使用途宝智能云仓
  10. </view>
  11. </view>
  12. <view class="login-view" style="">
  13. <view class="t-login">
  14. <form class="cl">
  15. <view class="t-a">
  16. <text class="txt">账户名</text>
  17. <input type="text" name="phone" placeholder="请输入您的账户名" maxlength="20" v-model="phone" />
  18. </view>
  19. <view class="t-a">
  20. <text class="txt">密码</text>
  21. <input type="password" name="code" maxlength="18" placeholder="请输入您的密码" v-model="pwd" />
  22. </view>
  23. <view>
  24. <u-checkbox-group>
  25. <u-checkbox v-model="checked" active-color="#2796f2" @change="change">记住密码</u-checkbox>
  26. </u-checkbox-group>
  27. </view>
  28. <u-button type="primary" class="custom-style" :ripple="true" @click="login">登 录</u-button>
  29. </form>
  30. </view>
  31. </view>
  32. <view style="position:absolute; bottom:20rpx;font-size: 20rpx;width: 100%;text-align: center;">
  33. 青岛途宝软件开发有限公司提供技术支持</view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. phone: '', //手机号码
  41. pwd: '', //密码
  42. checked: false,
  43. lifeData:{}
  44. }
  45. },
  46. onShow() {
  47. //清除本地缓存
  48. // uni.clearStorageSync();
  49. uni.removeStorageSync('lifeData');
  50. this.$u.vuex('vuex_token', '');
  51. console.log(uni.getStorageSync('lifeData'))
  52. this.phone = uni.getStorageSync('username')
  53. this.pwd = uni.getStorageSync('password')
  54. if (uni.getStorageSync('username')) {
  55. this.checked = true
  56. }
  57. },
  58. methods: {
  59. change(e) {
  60. console.log(e)
  61. },
  62. //当前登录按钮操作
  63. login() {
  64. let this_ = this
  65. this_.$u.post('/login', {
  66. username: this_.phone,
  67. password: this_.pwd
  68. }).then(res => {
  69. // console.log(res)
  70. if (res.code == 200) {
  71. if (this_.checked === true) {
  72. uni.setStorageSync('username', this_.phone);
  73. uni.setStorageSync('password', this_.pwd);
  74. }
  75. this_.lifeData = {
  76. vuex_token:res.token,
  77. vuex_user:this_.phone
  78. }
  79. uni.setStorage({
  80. key: 'lifeData',
  81. data: this_.lifeData,
  82. success(res) {
  83. uni.showToast({
  84. icon: 'none',
  85. title: '登录成功',
  86. position: "bottom"
  87. })
  88. this_.cacheData()
  89. }
  90. })
  91. // console.log(uni.getStorageSync('lifeData'))
  92. }
  93. })
  94. },
  95. cacheData(){
  96. this.$u.vuex('vuex_token', this.lifeData.vuex_token);
  97. // console.log(this.vuex_token)
  98. //跳转页面为tabBar页面
  99. uni.switchTab({
  100. url: '/pages/home/home'
  101. })
  102. }
  103. }
  104. };
  105. </script>
  106. <style scoped>
  107. .custom-style {
  108. color: #3ab2f7;
  109. margin-top: 140rpx;
  110. }
  111. .txt {
  112. font-size: 32rpx;
  113. font-weight: bold;
  114. color: #333333;
  115. }
  116. .img-a {
  117. width: 100%;
  118. height: 450rpx;
  119. background-image: url(../../static/head.png);
  120. background-size: 100%;
  121. }
  122. .reg {
  123. font-size: 28rpx;
  124. color: #fff;
  125. height: 90rpx;
  126. line-height: 90rpx;
  127. border-radius: 50rpx;
  128. font-weight: bold;
  129. background: #f5f6fa;
  130. color: #000000;
  131. text-align: center;
  132. margin-top: 30rpx;
  133. }
  134. .login-view {
  135. width: 100%;
  136. position: relative;
  137. margin-top: -120rpx;
  138. background-color: #ffffff;
  139. border-radius: 8% 8% 0% 0;
  140. }
  141. .t-login {
  142. width: 600rpx;
  143. margin: 0 auto;
  144. font-size: 28rpx;
  145. padding-top: 80rpx;
  146. }
  147. .t-login button {
  148. font-size: 28rpx;
  149. background: #2796f2;
  150. color: #fff;
  151. height: 90rpx;
  152. line-height: 90rpx;
  153. border-radius: 50rpx;
  154. font-weight: bold;
  155. }
  156. .t-login input {
  157. height: 90rpx;
  158. line-height: 90rpx;
  159. margin-bottom: 50rpx;
  160. border-bottom: 1px solid #e9e9e9;
  161. font-size: 28rpx;
  162. }
  163. .t-login .t-a {
  164. position: relative;
  165. }
  166. .t-b {
  167. text-align: left;
  168. font-size: 42rpx;
  169. color: #ffffff;
  170. padding: 130rpx 0 0 70rpx;
  171. font-weight: bold;
  172. line-height: 70rpx;
  173. }
  174. .t-login .t-c {
  175. position: absolute;
  176. right: 22rpx;
  177. top: 22rpx;
  178. background: #5677fc;
  179. color: #fff;
  180. font-size: 24rpx;
  181. border-radius: 50rpx;
  182. height: 50rpx;
  183. line-height: 50rpx;
  184. padding: 0 25rpx;
  185. }
  186. .t-login .t-d {
  187. text-align: center;
  188. color: #999;
  189. margin: 80rpx 0;
  190. }
  191. .t-login .t-e {
  192. text-align: center;
  193. width: 250rpx;
  194. margin: 80rpx auto 0;
  195. }
  196. .t-login .t-g {
  197. float: left;
  198. width: 50%;
  199. }
  200. .t-login .t-e image {
  201. width: 50rpx;
  202. height: 50rpx;
  203. }
  204. .t-login .t-f {
  205. text-align: center;
  206. margin: 150rpx 0 0 0;
  207. color: #666;
  208. }
  209. .t-login .t-f text {
  210. margin-left: 20rpx;
  211. color: #aaaaaa;
  212. font-size: 27rpx;
  213. }
  214. .t-login .uni-input-placeholder {
  215. color: #aeaeae;
  216. }
  217. .cl {
  218. zoom: 1;
  219. }
  220. .cl:after {
  221. clear: both;
  222. display: block;
  223. visibility: hidden;
  224. height: 0;
  225. content: '\20';
  226. }
  227. </style>