login.vue 6.9 KB

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