index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. customerList: [{
  73. id: 'tb-costomer-account',
  74. auth: true,
  75. icon: '../../static/home-icon-charge.png',
  76. text: '充值',
  77. url: '/pages/account/account-redirect',
  78. },
  79. {
  80. id: 'tb-declare',
  81. auth: false,
  82. icon: '../../static/home-icon-07.jpg',
  83. text: '申报录入',
  84. url: '/pages/declare/add',
  85. },
  86. {
  87. id: 'tb-disinfect',
  88. auth: false,
  89. icon: '../../static/home-icon-06.jpg',
  90. text: '消杀申报',
  91. url: '/pages/disinfect/addDisinfect',
  92. },
  93. {
  94. id: 'tb-business',
  95. auth: true,
  96. icon: '../../static/home-icon-02.png',
  97. text: '业务录入',
  98. url: '/pages/business-entering/business-entering',
  99. },
  100. {
  101. id: 'tb-business',
  102. auth: true,
  103. icon: '../../static/home-icon-03.png',
  104. text: '业务订单',
  105. url: '/pages/business-order/business-order',
  106. },
  107. {
  108. id: 'tb-business-car',
  109. auth: true,
  110. icon: '../../static/home-icon-05.png',
  111. text: '出入记录',
  112. url: '/pages/inout-record/inout-record',
  113. }
  114. ],
  115. adminList: [{
  116. id: 'tb-business',
  117. auth: true,
  118. icon: '../../static/home-icon-02.png',
  119. text: '业务录入',
  120. url: '/pages/business-entering/business-entering',
  121. },
  122. {
  123. id: 'tb-business',
  124. auth: true,
  125. icon: '../../static/home-icon-03.png',
  126. text: '业务订单',
  127. url: '/pages/business-order/business-order',
  128. },
  129. {
  130. id: 'tb-business-car',
  131. auth: true,
  132. icon: '../../static/home-icon-05.png',
  133. text: '出入记录',
  134. url: '/pages/inout-record/inout-record',
  135. },
  136. ]
  137. }
  138. },
  139. onLoad(options) {
  140. this.code = options.code;
  141. this.state = options.state;
  142. this.getOpenidByCode();
  143. },
  144. onShow() {
  145. this.loginByOpenid();
  146. this.checkUserType();
  147. },
  148. onBackPress() {
  149. return true;
  150. },
  151. methods: {
  152. checkPer(code) {
  153. console.log(code);
  154. console.log(this.$common.isAuth(code))
  155. return this.$common.isAuth(code);
  156. },
  157. getOpenidByCode() {
  158. if (!this.code) {
  159. this.$common.to('/pages/home/home')
  160. return;
  161. }
  162. let storeOpenid = uni.getStorageSync('openid');
  163. this.$api.getOpenidByCode({
  164. code: this.code,
  165. openid: storeOpenid
  166. }).then(resp => {
  167. let openid = resp.data;
  168. this.openid = openid;
  169. if (openid) {
  170. uni.setStorageSync('openid', openid)
  171. }
  172. this.loginByOpenid(openid)
  173. })
  174. },
  175. getStoreInfo() {
  176. let info = uni.getStorageSync('userInfo');
  177. if (info) {
  178. this.isLogin = true;
  179. this.userName = info.name;
  180. this.customerId = info.customerId;
  181. }
  182. },
  183. loginByOpenid() {
  184. let storeOpenid = uni.getStorageSync('openid');
  185. if (!storeOpenid) {
  186. return;
  187. }
  188. this.$api.doLoginByOpenid({
  189. openid: storeOpenid
  190. }).then(resp => {
  191. if (resp.code == 404) {
  192. return;
  193. }
  194. this.isLogin = true;
  195. let data = resp.data;
  196. this.userName = data.admin.name;
  197. this.customerId = data.admin.customerId;
  198. if (data.tokenInfo) {
  199. uni.setStorageSync('token', data.tokenInfo.tokenValue);
  200. uni.setStorageSync('customerId', data.admin.customerId)
  201. uni.setStorageSync('userInfo', data.admin)
  202. uni.setStorageSync('perList', data.per_list)
  203. this.checkUserType()
  204. } else {
  205. this.$common.toast(resp.msg);
  206. }
  207. })
  208. },
  209. checkUserType() {
  210. let token = uni.getStorageSync('token');
  211. if (token) {
  212. this.$nextTick(function() {
  213. this.$api.checkUserType().then(resp => {
  214. let userType = resp.data;
  215. if (userType == 3) {
  216. this.indexItemList = this.partnerList;
  217. } else if (userType == 2) { //客户
  218. this.indexItemList = this.customerList
  219. } else if (userType == 1) {
  220. this.indexItemList = this.adminList
  221. }
  222. })
  223. })
  224. }
  225. },
  226. toAccount() {
  227. if (this.customerId !== '1') {
  228. this.$common.to('/pages/customer-management/customer-list')
  229. }
  230. },
  231. getStoreInfo() {
  232. let info = uni.getStorageSync('userInfo');
  233. if (info) {
  234. this.isLogin = true;
  235. this.userName = info.name;
  236. this.customerId = info.customerId;
  237. }
  238. },
  239. toLogin() {
  240. this.$common.to('/pages/login/login')
  241. },
  242. exitFn() {
  243. uni.removeStorageSync('token')
  244. uni.removeStorageSync('userInfo')
  245. uni.removeStorageSync('customerId')
  246. uni.removeStorageSync('perList')
  247. let storeOpenid = uni.getStorageSync('openid');
  248. uni.setStorageSync('login_openid', storeOpenid);
  249. uni.removeStorageSync('openid')
  250. this.isLogin = false;
  251. this.userName = '';
  252. this.companyName = ''
  253. this.indexItemList = [{
  254. auth: false,
  255. icon: '../../static/home-icon-01.png',
  256. text: '企业注册',
  257. url: '/pages/enterprise-reg/enterprise-reg',
  258. customer:true
  259. }]
  260. },
  261. navTo(item) {
  262. let auth = item.auth;
  263. let token = uni.getStorageSync('token');
  264. if (!auth || token) {
  265. this.$common.to(item.url)
  266. } else {
  267. this.$common.to('/pages/login/login')
  268. }
  269. }
  270. }
  271. }
  272. </script>
  273. <style lang="scss">
  274. page {
  275. background-color: #fff;
  276. }
  277. .top-nav {
  278. position: fixed;
  279. top: 0;
  280. left: 0;
  281. right: 0;
  282. z-index: 999;
  283. display: flex;
  284. align-items: center;
  285. justify-content: space-between;
  286. padding: 20rpx 0;
  287. background-color: #0080ff;
  288. .l {
  289. display: flex;
  290. align-items: center;
  291. .login-btn {
  292. border: 1rpx solid #359aff;
  293. border-radius: 8rpx;
  294. color: #fff;
  295. padding: 10rpx 20rpx;
  296. font-size: 28rpx;
  297. margin-left: 30rpx;
  298. }
  299. .user-img {
  300. width: 80rpx;
  301. height: 80rpx;
  302. border-radius: 50%;
  303. margin-left: 30rpx;
  304. margin: 20rpx;
  305. }
  306. .l-r {
  307. display: flex;
  308. flex-direction: column;
  309. .u-name {
  310. font-size: 30rpx;
  311. color: #fff;
  312. font-weight: bold;
  313. }
  314. .c-name {
  315. font-size: 24rpx;
  316. color: #fff;
  317. }
  318. }
  319. }
  320. .r {
  321. display: flex;
  322. align-items: center;
  323. .l-out {
  324. border: 1rpx solid #359aff;
  325. border-radius: 8rpx;
  326. color: #c8e4ff;
  327. padding: 10rpx 20rpx;
  328. font-size: 28rpx;
  329. margin-right: 30rpx;
  330. }
  331. }
  332. }
  333. .top-bg {
  334. position: relative;
  335. top: 0;
  336. left: 0;
  337. right: 0;
  338. height: 400rpx;
  339. background-color: #0080ff;
  340. border-radius: 0 0 20rpx 20rpx;
  341. }
  342. .top {
  343. display: flex;
  344. width: 100%;
  345. align-items: center;
  346. justify-content: center;
  347. margin: 60rpx 0;
  348. margin-top: -400rpx;
  349. position: relative;
  350. z-index: 2;
  351. .title {
  352. font-size: 50rpx;
  353. font-weight: bold;
  354. color: #fff;
  355. }
  356. }
  357. .item-box {
  358. display: flex;
  359. flex-wrap: wrap;
  360. align-content: flex-start;
  361. padding: 40rpx;
  362. box-sizing: border-box;
  363. background-color: #fff;
  364. margin: 0 30rpx;
  365. border-radius: 20rpx;
  366. position: relative;
  367. z-index: 2;
  368. //height: calc(100vh - 170rpx - 500rpx);
  369. box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.03);
  370. .item {
  371. width: 25%;
  372. display: flex;
  373. flex-direction: column;
  374. align-items: center;
  375. justify-content: center;
  376. padding: 40rpx 0;
  377. .icon {
  378. width: 90rpx;
  379. height: 90rpx;
  380. }
  381. .text {
  382. font-size: 28rpx;
  383. color: #191919;
  384. margin-top: 20rpx;
  385. }
  386. }
  387. }
  388. .qrcode {
  389. display: flex;
  390. width: 100%;
  391. flex-direction: column;
  392. align-items: center;
  393. justify-content: center;
  394. margin: 30rpx 0;
  395. .qrcode {
  396. width: 350rpx;
  397. height: 350rpx;
  398. border: 1px solid #191919;
  399. }
  400. .text {
  401. color: #191919;
  402. font-size: 28rpx;
  403. margin-top: 5rpx;
  404. }
  405. }
  406. </style>