index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <template>
  2. <view>
  3. <view class="top-nav">
  4. <view class="l">
  5. <block v-if="isLogin">
  6. <image class="user-img" src="../../static/user.png" @click="toAccount"></image>
  7. <view class="l-r">
  8. <text class="u-name">{{userName}}</text>
  9. <text class="c-name" v-if="customerId!=='1'">{{companyName}}</text>
  10. </view>
  11. </block>
  12. <block v-else>
  13. <view class="login-btn" @click="toLogin">登录</view>
  14. </block>
  15. </view>
  16. <view class="r" v-if="isLogin">
  17. <view class="l-out" @click="exitFn">
  18. 退出登录
  19. </view>
  20. </view>
  21. </view>
  22. <view class="top-bg"></view>
  23. <view class="top">
  24. <text class="title">场站管理系统</text>
  25. </view>
  26. <view class="item-box">
  27. <view class="item" hover-class="hover-class" v-for="(indexItem,index) in indexItemList" :key="index"
  28. @click="navTo(indexItem)" v-if="checkPer(indexItem.id)||indexItem.customer">
  29. <image class="icon" :src="indexItem.icon"></image>
  30. <view class="text">
  31. <text v-if="indexItem.text=='企业管理'&&customerId!='1'">信息管理</text>
  32. <text v-else>{{indexItem.text}}</text>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="qrcode">
  37. <image class="qrcode" :src="qrcoderlc"></image>
  38. <text class="text">长按二维码保存分享</text>
  39. </view>
  40. <view style="text-align: center;font-size: 23rpx;">
  41. <a href="https://beian.miit.gov.cn/" target="_blank">桂ICP备12007573号-1</a>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. isLogin: false, //是否登录状态
  50. userName: '',
  51. companyName: '',
  52. customerId: '',
  53. qrcoderlc: '../../static/qrcode.png',
  54. indexItemList: [{
  55. auth: false,
  56. icon: '../../static/home-icon-01.png',
  57. text: '企业注册',
  58. url: '/pages/enterprise-reg/enterprise-reg',
  59. customer:true
  60. }],
  61. code: '',
  62. state: '',
  63. userType: 1,
  64. partnerList: [
  65. {
  66. id:'tb-business-item',
  67. auth: true,
  68. icon: '../../static/home-icon-03.png',
  69. text: '我的业务',
  70. url: '/pages/business-order/partner-business-item',
  71. },
  72. {
  73. id:'admin-list',
  74. auth: true,
  75. icon: '../../static/home-icon-04.png',
  76. text: '用户管理',
  77. url: '/pages/user/user-index',
  78. },
  79. ],
  80. customerList: [{
  81. id: 'tb-costomer-account',
  82. auth: true,
  83. icon: '../../static/home-icon-charge.png',
  84. text: '充值',
  85. url: '/pages/account/account-redirect',
  86. },
  87. {
  88. id: 'tb-declare',
  89. auth: false,
  90. icon: '../../static/home-icon-07.jpg',
  91. text: '申报录入',
  92. url: '/pages/declare/add',
  93. },
  94. {
  95. id: 'tb-disinfect',
  96. auth: false,
  97. icon: '../../static/home-icon-06.jpg',
  98. text: '消杀申报',
  99. url: '/pages/disinfect/addDisinfect',
  100. },
  101. {
  102. id: 'tb-business',
  103. auth: true,
  104. icon: '../../static/home-icon-02.png',
  105. text: '业务录入',
  106. url: '/pages/business-entering/business-entering',
  107. },
  108. {
  109. id: 'tb-business',
  110. auth: true,
  111. icon: '../../static/home-icon-03.png',
  112. text: '业务订单',
  113. url: '/pages/business-order/business-order',
  114. },
  115. {
  116. id: 'tb-business-car',
  117. auth: true,
  118. icon: '../../static/home-icon-05.png',
  119. text: '放行记录',
  120. url: '/pages/inout-record/inout-record',
  121. },
  122. {
  123. id:'admin-list',
  124. auth: true,
  125. icon: '../../static/home-icon-04.png',
  126. text: '用户管理',
  127. url: '/pages/user/user-index',
  128. },
  129. ],
  130. adminList: [{
  131. id: 'tb-business-add',
  132. auth: true,
  133. icon: '../../static/home-icon-02.png',
  134. text: '业务录入',
  135. url: '/pages/business-entering/business-entering',
  136. },
  137. {
  138. id: 'tb-business-list',
  139. auth: true,
  140. icon: '../../static/home-icon-03.png',
  141. text: '业务订单',
  142. url: '/pages/business-order/business-order',
  143. },
  144. {
  145. id: 'tb-business-car',
  146. auth: true,
  147. icon: '../../static/home-icon-05.png',
  148. text: '放行记录',
  149. url: '/pages/inout-record/inout-record',
  150. },
  151. {
  152. id:'admin-list',
  153. auth: true,
  154. icon: '../../static/home-icon-04.png',
  155. text: '用户管理',
  156. url: '/pages/user/user-index',
  157. },
  158. ]
  159. }
  160. },
  161. onLoad(options) {
  162. this.code = options.code;
  163. this.state = options.state;
  164. this.getOpenidByCode();
  165. },
  166. onShow() {
  167. this.loginByOpenid();
  168. this.checkUserType();
  169. },
  170. onBackPress() {
  171. return true;
  172. },
  173. methods: {
  174. checkPer(code) {
  175. return this.$common.isAuth(code);
  176. },
  177. getOpenidByCode() {
  178. if (!this.code) {
  179. this.$common.to('/pages/home/home')
  180. return;
  181. }
  182. let storeOpenid = uni.getStorageSync('openid');
  183. this.$api.getOpenidByCode({
  184. code: this.code,
  185. openid: storeOpenid
  186. }).then(resp => {
  187. this.success=resp.code==200&&resp.data?1:0
  188. if(resp.code==200&&resp.data){
  189. this.success=1;
  190. }else{
  191. this.success=0
  192. }
  193. let openid = resp.data;
  194. this.openid = openid;
  195. if (openid) {
  196. uni.setStorageSync('openid', openid)
  197. }
  198. this.loginByOpenid(openid)
  199. })
  200. },
  201. getStoreInfo() {
  202. let info = uni.getStorageSync('userInfo');
  203. if (info) {
  204. this.isLogin = true;
  205. this.userName = info.name;
  206. this.customerId = info.customerId;
  207. }
  208. },
  209. loginByOpenid() {
  210. let storeOpenid = uni.getStorageSync('openid');
  211. if (!storeOpenid) {
  212. return;
  213. }
  214. this.$api.doLoginByOpenid({
  215. openid: storeOpenid
  216. }).then(resp => {
  217. if (resp.code == 404) {
  218. return;
  219. }
  220. this.isLogin = true;
  221. let data = resp.data;
  222. this.userName = data.admin.name;
  223. this.customerId = data.admin.customerId;
  224. if (data.tokenInfo) {
  225. uni.setStorageSync('token', data.tokenInfo.tokenValue);
  226. uni.setStorageSync('customerId', data.admin.customerId)
  227. uni.setStorageSync('userInfo', data.admin)
  228. uni.setStorageSync('perList', data.per_list)
  229. this.checkUserType()
  230. } else {
  231. this.$common.toast(resp.msg);
  232. }
  233. })
  234. },
  235. checkUserType() {
  236. let token = uni.getStorageSync('token');
  237. if (token) {
  238. this.$nextTick(function() {
  239. this.$api.checkUserType().then(resp => {
  240. let userType = resp.data;
  241. if (userType == 3) {
  242. this.indexItemList = this.partnerList;
  243. } else if (userType == 2) { //客户
  244. this.indexItemList = this.customerList
  245. } else if (userType == 1) {
  246. this.indexItemList = this.adminList
  247. }
  248. })
  249. })
  250. }
  251. },
  252. toAccount() {
  253. if (this.customerId !== '1') {
  254. this.$common.to('/pages/customer-management/customer-list')
  255. }
  256. },
  257. getStoreInfo() {
  258. let info = uni.getStorageSync('userInfo');
  259. if (info) {
  260. this.isLogin = true;
  261. this.userName = info.name;
  262. this.customerId = info.customerId;
  263. }
  264. },
  265. toLogin() {
  266. this.$common.to('/pages/login/login')
  267. },
  268. exitFn() {
  269. uni.removeStorageSync('token')
  270. uni.removeStorageSync('userInfo')
  271. uni.removeStorageSync('customerId')
  272. uni.removeStorageSync('perList')
  273. let storeOpenid = uni.getStorageSync('openid');
  274. uni.setStorageSync('login_openid', storeOpenid);
  275. uni.removeStorageSync('openid')
  276. this.isLogin = false;
  277. this.userName = '';
  278. this.companyName = ''
  279. this.indexItemList = [{
  280. auth: false,
  281. icon: '../../static/home-icon-01.png',
  282. text: '企业注册',
  283. url: '/pages/enterprise-reg/enterprise-reg',
  284. customer:true
  285. }]
  286. },
  287. navTo(item) {
  288. let auth = item.auth;
  289. let token = uni.getStorageSync('token');
  290. if (!auth || token) {
  291. this.$common.to(item.url)
  292. } else {
  293. this.$common.to('/pages/login/login')
  294. }
  295. }
  296. }
  297. }
  298. </script>
  299. <style lang="scss">
  300. page {
  301. background-color: #fff;
  302. }
  303. .top-nav {
  304. position: fixed;
  305. top: 0;
  306. left: 0;
  307. right: 0;
  308. z-index: 999;
  309. display: flex;
  310. align-items: center;
  311. justify-content: space-between;
  312. padding: 20rpx 0;
  313. background-color: #0080ff;
  314. .l {
  315. display: flex;
  316. align-items: center;
  317. .login-btn {
  318. border: 1rpx solid #359aff;
  319. border-radius: 8rpx;
  320. color: #fff;
  321. padding: 10rpx 20rpx;
  322. font-size: 28rpx;
  323. margin-left: 30rpx;
  324. }
  325. .user-img {
  326. width: 80rpx;
  327. height: 80rpx;
  328. border-radius: 50%;
  329. margin-left: 30rpx;
  330. margin: 20rpx;
  331. }
  332. .l-r {
  333. display: flex;
  334. flex-direction: column;
  335. .u-name {
  336. font-size: 30rpx;
  337. color: #fff;
  338. font-weight: bold;
  339. }
  340. .c-name {
  341. font-size: 24rpx;
  342. color: #fff;
  343. }
  344. }
  345. }
  346. .r {
  347. display: flex;
  348. align-items: center;
  349. .l-out {
  350. border: 1rpx solid #359aff;
  351. border-radius: 8rpx;
  352. color: #c8e4ff;
  353. padding: 10rpx 20rpx;
  354. font-size: 28rpx;
  355. margin-right: 30rpx;
  356. }
  357. }
  358. }
  359. .top-bg {
  360. position: relative;
  361. top: 0;
  362. left: 0;
  363. right: 0;
  364. height: 400rpx;
  365. background-color: #0080ff;
  366. border-radius: 0 0 20rpx 20rpx;
  367. }
  368. .top {
  369. display: flex;
  370. width: 100%;
  371. align-items: center;
  372. justify-content: center;
  373. margin: 60rpx 0;
  374. margin-top: -400rpx;
  375. position: relative;
  376. z-index: 2;
  377. .title {
  378. font-size: 50rpx;
  379. font-weight: bold;
  380. color: #fff;
  381. }
  382. }
  383. .item-box {
  384. display: flex;
  385. flex-wrap: wrap;
  386. align-content: flex-start;
  387. padding: 40rpx;
  388. box-sizing: border-box;
  389. background-color: #fff;
  390. margin: 0 30rpx;
  391. border-radius: 20rpx;
  392. position: relative;
  393. z-index: 2;
  394. //height: calc(100vh - 170rpx - 500rpx);
  395. box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.03);
  396. .item {
  397. width: 25%;
  398. display: flex;
  399. flex-direction: column;
  400. align-items: center;
  401. justify-content: center;
  402. padding: 40rpx 0;
  403. .icon {
  404. width: 90rpx;
  405. height: 90rpx;
  406. }
  407. .text {
  408. font-size: 28rpx;
  409. color: #191919;
  410. margin-top: 20rpx;
  411. }
  412. }
  413. }
  414. .qrcode {
  415. display: flex;
  416. width: 100%;
  417. flex-direction: column;
  418. align-items: center;
  419. justify-content: center;
  420. margin: 30rpx 0;
  421. .qrcode {
  422. width: 350rpx;
  423. height: 350rpx;
  424. border: 1px solid #191919;
  425. }
  426. .text {
  427. color: #191919;
  428. font-size: 28rpx;
  429. margin-top: 5rpx;
  430. }
  431. }
  432. </style>