login.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view class="body2">
  3. <u-navbar title="湖里区不可移动文物数字化监管平台" bgColor="#071d4f" :leftIconSize="0" titleStyle=" font-weight:bold;color:#25d7f2"></u-navbar>
  4. <block>
  5. <!-- #ifndef MP-WEIXIN -->
  6. <view class="login-bg">
  7. <view class="login-card">
  8. <view class="login-head">
  9. <image class="logoimg" src="@/static/img/safe.png" mode="widthFix"></image>
  10. </view>
  11. <view class="login-input login-margin-b">
  12. <input v-model="username" placeholder="请输入手机号" />
  13. </view>
  14. <view class="login-input">
  15. <!-- <input :password="true" v-model="password" placeholder="请输入密码(6-16位)" /> -->
  16. <input v-model="password" placeholder="请输入密码(6-16位)" :password="showPassword" />
  17. <u-icon style="position: absolute; right: 40rpx; top: 40rpx" name="eye" :class="[!showPassword ? 'uni-eye-active' : '']" @click="changePassword"></u-icon>
  18. </view>
  19. <view class="cu-bar btn-group gui-margin-top-large">
  20. <button class="loginBtn bg-orange shadow-blur round" :loading="loading" @tap="login">{{ loading ? '登录中...' : '登 录' }}</button>
  21. </view>
  22. <!-- <view class="flex justify-center">
  23. <view class="text-gray text-sm margin-top-xl" @tap="register">注册新账户</view>
  24. </view> -->
  25. </view>
  26. </view>
  27. <!-- #endif -->
  28. <!-- #ifdef MP-WEIXIN -->
  29. </block>
  30. </view>
  31. </template>
  32. <script>
  33. var _this;
  34. export default {
  35. data() {
  36. return {
  37. showPassword: true,
  38. loading: false,
  39. user: [],
  40. username: '',
  41. password: '',
  42. class_id: '',
  43. ismobile: false,
  44. group_id: 1,
  45. code: '',
  46. redirect: '',
  47. userAgent: navigator.userAgent
  48. };
  49. },
  50. mounted() {
  51. _this = this;
  52. },
  53. onLoad(e) {
  54. console.log(e);
  55. if (e.redirect) {
  56. this.redirect = e.redirect;
  57. }
  58. },
  59. onShow() {
  60. this.user = this.$common.userInfo();
  61. console.log('this.user: ', this.user);
  62. if (typeof this.user == 'undefined' || this.user == '' || this.user == null) {
  63. } else {
  64. this.$common.navigateTo('index');
  65. }
  66. // #ifdef MP-WEIXIN
  67. this.wxLogin();
  68. // #endif
  69. },
  70. methods: {
  71. changePassword: function () {
  72. this.showPassword = !this.showPassword;
  73. },
  74. wxLogin() {
  75. wx.login({
  76. success: (res) => {
  77. this.code = res.code;
  78. },
  79. fail: function (error) {
  80. console.log('login failed ' + error);
  81. }
  82. });
  83. },
  84. register() {
  85. this.$common.navigateTo('register');
  86. },
  87. login() {
  88. _this.loading = true;
  89. // if (_this.username == '' || _this.username.length < 11) {
  90. // uni.showToast({
  91. // icon: 'none',
  92. // title: '请输入正确的手机号'
  93. // });
  94. // _this.loading = false;
  95. // return;
  96. // }
  97. if (_this.password == '') {
  98. uni.showToast({
  99. icon: 'none',
  100. title: '请输入密码'
  101. });
  102. _this.loading = false;
  103. return;
  104. }
  105. _this.$api.login(
  106. {
  107. account: _this.username,
  108. password: _this.password
  109. },
  110. (data) => {
  111. console.log(data);
  112. if (data.code == 1) {
  113. _this.loading = false;
  114. console.log(data, 11);
  115. _this.$common.successToShow(data.msg, function () {
  116. _this.$common.navigateTo('index');
  117. uni.switchTab({
  118. url: '/pages/index/index'
  119. });
  120. // if (_this.userAgent.match(/Windows/i)) {
  121. // console.log('用户使用的是Windows操作系统');
  122. // uni.navigateTo({
  123. // url: '/pages/index/index2'
  124. // });
  125. // } else if (_this.userAgent.match(/Linux/i)) {
  126. // console.log('用户使用的是Linux操作系统');
  127. // uni.switchTab({
  128. // url: '/pages/index/index'
  129. // });
  130. // }
  131. });
  132. try {
  133. _this.$db.set('upload', 1);
  134. _this.$db.set('login', 1);
  135. _this.$db.set('token', data.data.userinfo.token);
  136. _this.$db.set('user', data.data.userinfo);
  137. _this.$db.set('auth', data.data.userinfo);
  138. _this.$store.commit('setAccessToken', data.data.userinfo.token);
  139. _this.$store.commit('setActivityId', 0);
  140. } catch (e) {}
  141. } else {
  142. _this.loading = false;
  143. uni.showToast({
  144. duration: 1500,
  145. icon: 'none',
  146. title: data.msg
  147. });
  148. }
  149. }
  150. );
  151. }
  152. }
  153. };
  154. </script>
  155. <style>
  156. /deep/.u-line-1 {
  157. width: 800rpx !important;
  158. }
  159. .body2 {
  160. width: 100%;
  161. height: 1939rpx;
  162. font-size: 28upx;
  163. color: #ffffff;
  164. font-family: Helvetica Neue, Helvetica, sans-serif;
  165. background: url('@/static/img/MainBack.png') no-repeat center;
  166. background-size: 100% 100%;
  167. background-attachment: fixed;
  168. background-repeat: repeat-y;
  169. }
  170. .logView {
  171. display: flex;
  172. align-items: center;
  173. justify-content: center;
  174. flex-direction: column;
  175. align-items: center;
  176. /* 垂直居中 */
  177. width: 100%;
  178. position: fixed;
  179. left: 50%;
  180. top: 50%;
  181. transform: translate(-50%, -50%);
  182. }
  183. .logbt {
  184. display: flex;
  185. align-items: center;
  186. justify-content: center;
  187. flex-direction: column;
  188. align-items: center;
  189. /* 垂直居中 */
  190. width: 100%;
  191. background: none;
  192. border: none !important;
  193. }
  194. .logbt:after {
  195. border: none !important;
  196. }
  197. .logbt .logoimg {
  198. width: 200rpx;
  199. height: 200rpx;
  200. display: block;
  201. }
  202. .loginBtn {
  203. width: 800rpx;
  204. height: 100rpx;
  205. line-height: 100rpx;
  206. color: #fff;
  207. background: #123469;
  208. border-radius: 10rpx;
  209. border: none;
  210. }
  211. image {
  212. width: 100rpx;
  213. height: 100rpx;
  214. }
  215. .login-btn {
  216. padding: 10rpx 20rpx;
  217. margin-top: 60rpx;
  218. }
  219. .login-register {
  220. color: #666;
  221. float: right;
  222. font-size: 26rpx;
  223. }
  224. .login-input input {
  225. background: #c2c4c5;
  226. font-size: 28rpx;
  227. padding: 10rpx 25rpx;
  228. height: 80rpx !important;
  229. line-height: 80rpx;
  230. border-radius: 40rpx;
  231. }
  232. .login-margin-b {
  233. margin-bottom: 25rpx;
  234. }
  235. .login-input {
  236. padding: 10rpx 20rpx;
  237. position: relative;
  238. }
  239. .login-head {
  240. font-size: 34rpx;
  241. text-align: center;
  242. padding: 25rpx 10rpx 55rpx 10rpx;
  243. }
  244. .login-head image {
  245. width: 200rpx;
  246. }
  247. .login-card {
  248. background: rgba(0, 0, 0, 0.3);
  249. border-radius: 12rpx;
  250. padding: 10rpx 25rpx;
  251. position: relative;
  252. margin-top: 120rpx;
  253. width: 500px;
  254. }
  255. .login-bg {
  256. margin: 0 auto;
  257. height: 500px;
  258. padding: 25rpx;
  259. width: 600px;
  260. display: flex;
  261. justify-content: center;
  262. }
  263. </style>