login.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view class="body">
  3. <u-navbar title="文物管理街道分中心" bgColor="rgba(255,255,255,0.3)" :leftIconSize="0" titleStyle="font-weight:bold;color:#7a5831"></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="baseLogo" mode="widthFix"></image>
  10. </view>
  11. <view class="login-input login-margin-b">
  12. <input type="number" v-model="username" placeholder="请输入手机号" />
  13. </view>
  14. <view class="login-input">
  15. <input :password="true" v-model="password" placeholder="请输入密码(6-16位)" />
  16. </view>
  17. <view class="cu-bar btn-group gui-margin-top-large">
  18. <button class="loginBtn bg-orange shadow-blur round" :loading="loading" @tap="login">{{ loading ? '登录中...' : '登 录' }}</button>
  19. </view>
  20. <!-- <view class="flex justify-center">
  21. <view class="text-gray text-sm margin-top-xl" @tap="register">注册新账户</view>
  22. </view> -->
  23. </view>
  24. </view>
  25. <!-- #endif -->
  26. <!-- #ifdef MP-WEIXIN -->
  27. <view class="logView">
  28. <button @click="onGetUserProfile" class="logbt">
  29. <view class="login-head">
  30. <image class="logoimg" :src="baseLogo" mode="widthFix"></image>
  31. </view>
  32. <view class="loginTitile"><text decode="true">请点击微信登录,并授权获取公开信息, 登录后您将获得更多权益</text></view>
  33. <view class="cu-btn bg-orange shadow-blur round">
  34. <text class="cuIcon-lightauto"></text>
  35. 微信登录
  36. </view>
  37. </button>
  38. <!-- <view class="text-gray text-sm margin-top-xl" @click="changMobileLogin()">手机登录</view> -->
  39. </view>
  40. <!-- #endif -->
  41. </block>
  42. </view>
  43. </template>
  44. <script>
  45. var _this;
  46. import { baseLogo } from '../../config/config.js';
  47. export default {
  48. data() {
  49. return {
  50. loading: false,
  51. user: [],
  52. username: '',
  53. password: '',
  54. class_id: '',
  55. ismobile: false,
  56. group_id: 1,
  57. code: '',
  58. baseLogo: baseLogo,
  59. redirect: ''
  60. };
  61. },
  62. mounted() {
  63. _this = this;
  64. },
  65. onLoad(e) {
  66. console.log(e);
  67. if (e.redirect) {
  68. this.redirect = e.redirect;
  69. }
  70. },
  71. onShow() {
  72. this.user = this.$common.userInfo();
  73. console.log('this.user: ', this.user);
  74. if (typeof this.user == 'undefined' || this.user == '' || this.user == null) {
  75. } else {
  76. this.$common.navigateTo('index');
  77. }
  78. // #ifdef MP-WEIXIN
  79. this.wxLogin();
  80. // #endif
  81. },
  82. methods: {
  83. wxLogin() {
  84. wx.login({
  85. success: (res) => {
  86. this.code = res.code;
  87. },
  88. fail: function (error) {
  89. console.log('login failed ' + error);
  90. }
  91. });
  92. },
  93. //切换微信登录
  94. // wechatLogin(){
  95. // _this.ismobile=false;
  96. // },
  97. //切换手机登录
  98. // changMobileLogin(){
  99. // _this.ismobile=true;
  100. // },
  101. register() {
  102. this.$common.navigateTo('register');
  103. },
  104. login() {
  105. // _this.loading = true;
  106. // if (_this.username == '' || _this.username.length < 11) {
  107. // uni.showToast({
  108. // icon: 'none',
  109. // title: '请输入正确的手机号'
  110. // });
  111. // _this.loading = false;
  112. // return;
  113. // }
  114. // if (_this.password == '') {
  115. // uni.showToast({
  116. // icon: 'none',
  117. // title: '请输入密码'
  118. // });
  119. // _this.loading = false;
  120. // return;
  121. // }
  122. // _this.$api.login(
  123. // {
  124. // account: _this.username,
  125. // password: _this.password
  126. // },
  127. // (data) => {
  128. // //console.log(data);
  129. // if (data.code == 1) {
  130. // _this.loading = false;
  131. // //console.log(data);
  132. // _this.$common.successToShow(data.msg, function () {
  133. // // _this.$common.navigateTo('index');
  134. uni.switchTab({
  135. url: '/pages/index/index'
  136. });
  137. // });
  138. // try {
  139. // _this.$db.set('upload', 1);
  140. // _this.$db.set('login', 1);
  141. // _this.$db.set('token', data.data.userinfo.token);
  142. // _this.$db.set('user', data.data.userinfo);
  143. // _this.$db.set('auth', data.data.auth);
  144. // _this.$store.commit('setAccessToken', data.data.userinfo.token);
  145. // _this.$store.commit('setActivityId', 0);
  146. // } catch (e) {}
  147. // } else {
  148. // _this.loading = false;
  149. // uni.showToast({
  150. // duration: 1500,
  151. // icon: 'none',
  152. // title: data.msg
  153. // });
  154. // }
  155. // }
  156. // );
  157. },
  158. onGetUserProfile() {
  159. // uni.showLoading({
  160. // title:"正在登录中..."
  161. // })
  162. var platform = 'wechat';
  163. var that = this;
  164. var fid = uni.getStorageSync('parentid') ? uni.getStorageSync('parentid') : '';
  165. uni.getUserProfile({
  166. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  167. success: (res) => {
  168. console.log(res);
  169. _this.$api.third(
  170. {
  171. code: _this.code,
  172. platform: platform,
  173. encrypted_data: res.encryptedData,
  174. iv: res.iv,
  175. raw_data: res.rawData,
  176. signature: res.signature,
  177. appid: 'wx98c89e5f918af88f'
  178. },
  179. (data) => {
  180. console.log(data);
  181. // console.log(data.data.userinfo)
  182. var res = data.data;
  183. if (data.code == 1) {
  184. this.$common.successToShow('登录成功!');
  185. try {
  186. this.$db.set('upload', 1);
  187. this.$db.set('login', 1);
  188. this.$db.set('auth', res.auth);
  189. this.$db.set('user', res.userinfo);
  190. this.$store.commit('setAccessToken', res.auth.token);
  191. //this.$store.commit('setActivityId', 0)
  192. } catch (e) {
  193. console.log('e: ', e);
  194. }
  195. // uni.switchTab({
  196. // url: '/pages/index/index'
  197. // });
  198. if (this.redirect != '') {
  199. console.log(this.redirect);
  200. this.$common.navigateTo(this.redirect);
  201. return;
  202. }
  203. uni.navigateBack();
  204. } else {
  205. _this.wxLogin();
  206. }
  207. }
  208. );
  209. },
  210. fail: (res) => {
  211. console.log('res: ', res);
  212. _this.wxLogin(); //重新获取登录code
  213. uni.hideLoading();
  214. if (res.errMsg == 'getUserInfo:cancel' || res.errMsg == 'getUserInfo:fail auth deny') {
  215. uni.showModal({
  216. title: '用户授权失败',
  217. showCancel: false,
  218. content: '请点击重新授权,如果未弹出授权,请尝试长按删除小程序,重新进入!',
  219. success: function (res) {
  220. if (res.confirm) {
  221. console.log('用户点击确定');
  222. uni.navigateBack();
  223. }
  224. }
  225. });
  226. }
  227. }
  228. });
  229. // uni.login({
  230. // success: loginRes => {
  231. // uni.hideLoading();
  232. // console.log('第一次登录'+loginRes.code)
  233. // if (loginRes.code && loginRes.code!='') {
  234. // console.log('2222222222222222222')
  235. // }
  236. // }
  237. // })
  238. }
  239. }
  240. };
  241. </script>
  242. <style>
  243. .content {
  244. height: 100%;
  245. }
  246. .logView {
  247. display: flex;
  248. align-items: center;
  249. justify-content: center;
  250. flex-direction: column;
  251. align-items: center;
  252. /* 垂直居中 */
  253. width: 100%;
  254. position: fixed;
  255. left: 50%;
  256. top: 50%;
  257. transform: translate(-50%, -50%);
  258. }
  259. .logbt {
  260. display: flex;
  261. align-items: center;
  262. justify-content: center;
  263. flex-direction: column;
  264. align-items: center;
  265. /* 垂直居中 */
  266. width: 100%;
  267. background: none;
  268. border: none !important;
  269. }
  270. .logbt:after {
  271. border: none !important;
  272. }
  273. .logbt .logoimg {
  274. width: 200rpx;
  275. height: 200rpx;
  276. display: block;
  277. }
  278. .logbt .wechatimg {
  279. width: 150rpx;
  280. height: 150rpx;
  281. display: block;
  282. }
  283. .loginTitile {
  284. padding: 50rpx;
  285. font-size: 28rpx;
  286. color: #787878;
  287. line-height: 1.3;
  288. text-align: center;
  289. }
  290. .loginBtn {
  291. width: 600rpx;
  292. height: 70rpx;
  293. line-height: 70rpx;
  294. color: #fff;
  295. background: #aa6d03;
  296. border-radius: 10rpx;
  297. border: none;
  298. }
  299. image {
  300. width: 100rpx;
  301. height: 100rpx;
  302. }
  303. .mobileLogin {
  304. background: none;
  305. color: #999;
  306. text-align: center;
  307. margin: 40rpx auto;
  308. border: none;
  309. font-size: 26rpx;
  310. }
  311. .landing[type='primary'] {
  312. height: 84rpx;
  313. line-height: 84rpx;
  314. border-radius: 44rpx;
  315. font-size: 32rpx;
  316. /* background: linear-gradient(left, #86B5F4, #4790EF); */
  317. background-color: #ffbc32;
  318. }
  319. .login-btn {
  320. padding: 10rpx 20rpx;
  321. margin-top: 60rpx;
  322. }
  323. .login-function {
  324. overflow: auto;
  325. padding: 20rpx 20rpx 30rpx 20rpx;
  326. }
  327. .login-forget {
  328. float: left;
  329. font-size: 26rpx;
  330. color: #999;
  331. }
  332. .login-register {
  333. color: #666;
  334. float: right;
  335. font-size: 26rpx;
  336. }
  337. .login-input input {
  338. background: #f2f5f6;
  339. font-size: 28rpx;
  340. padding: 10rpx 25rpx;
  341. height: 80rpx;
  342. line-height: 80rpx;
  343. border-radius: 40rpx;
  344. }
  345. .login-margin-b {
  346. margin-bottom: 25rpx;
  347. }
  348. .login-input {
  349. padding: 10rpx 20rpx;
  350. }
  351. .login-head {
  352. font-size: 34rpx;
  353. text-align: center;
  354. padding: 25rpx 10rpx 55rpx 10rpx;
  355. }
  356. .login-head image {
  357. width: 200rpx;
  358. }
  359. .login-card {
  360. background: #fff;
  361. border-radius: 12rpx;
  362. padding: 10rpx 25rpx;
  363. position: relative;
  364. margin-top: 120rpx;
  365. width: 500px;
  366. }
  367. .login-bg {
  368. margin: 0 auto;
  369. height: 500px;
  370. padding: 25rpx;
  371. width: 600px;
  372. display: flex;
  373. justify-content: center;
  374. }
  375. </style>