home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <template>
  2. <view class="container">
  3. <!-- 自定义导航栏区域 -->
  4. <view class="tab" :style="{ height: customBarH * 2 + 'rpx', paddingTop: statusBarH * 2 + 'rpx' }" v-show="!showHeader">
  5. <img class="tab_img" src="../../static/images/people.png" @click="goPage('/pages/myCenter/myCenter')" />
  6. 万载三中
  7. </view>
  8. <!-- 页面下拉时显示的导航栏 -->
  9. <view class="tab2" :style="{ height: customBarH * 2 + 'rpx', paddingTop: statusBarH * 2 + 'rpx' }" v-show="showHeader">万载三中</view>
  10. <!-- 顶部图片区域 -->
  11. <view class="header">
  12. <img mode="aspectFill" class="header_img" src="../../static/images/header.png" />
  13. <!-- 学校图标区域 -->
  14. <img mode="aspectFill" class="header_icon" src="../../static/images/school-logo.jpg" />
  15. <!-- 学校名称区域 -->
  16. <view class="header_school">万载县第三中学</view>
  17. <!-- 学生姓名区域 -->
  18. <view class="header_name">{{ userInfo.name }}</view>
  19. <!-- 学生年级区域 -->
  20. <view class="header_grade" v-if="userInfo.identityId == 1">家长</view>
  21. <view class="header_grade" v-if="userInfo.identityId == 2">学生</view>
  22. <view class="header_grade" v-if="userInfo.identityId == 3">教师</view>
  23. <!-- 二维码区域 -->
  24. <view class="header_code">
  25. <uv-qrcode ref="qrcodeRef" size="82rpx" :value="QRCodeUrl" :options="options" @click="handleClickCode"></uv-qrcode>
  26. </view>
  27. </view>
  28. <!-- 详细信息区域 -->
  29. <view class="body">
  30. <!-- 个人信息区域 -->
  31. <view class="body_header" v-if="userInfo.identityId == 1">
  32. <img class="info_bg" src="../../static/images/info-bg.png" />
  33. <img v-if="childMsgList.length" mode="aspectFill" class="info_img" :src="currentChild.headImage || '../../static/images/user-photo.png'" />
  34. <view v-if="childMsgList.length" class="info_name">{{ currentChild.name }}</view>
  35. <view v-if="childMsgList.length" class="info_detail" @click="goPage(`/pages/myMsg/myMsg?id=${currentChild.id}`)">孩子信息></view>
  36. <view v-if="childMsgList.length > 1" class="info_change" @click="goPage(`/pages/change/change?list=${JSON.stringify(childMsgList)}&id=${currentChild.id}`)">
  37. 切换 >
  38. </view>
  39. <view v-if="!childMsgList.length" class="info_no">暂无孩子绑定</view>
  40. <!-- 关联区域 -->
  41. <view class="info_bind">
  42. <img @click="goPage('/pages/bind/bind')" class="bind_img" src="../../static/images/bind.png" />
  43. <text @click="goPage('/pages/bind/bind')">关联小孩</text>
  44. </view>
  45. </view>
  46. <!-- 应用列表区域 -->
  47. <view class="body_list" v-if="useAppList.length">
  48. <!-- 每一个应用区域 -->
  49. <view class="list_box" v-for="item in useAppList" :key="item.id" @click="goPage(item.path, item)">
  50. <img class="box_img" :src="item.url" />
  51. <view class="box_text">
  52. {{ item.title }}
  53. </view>
  54. </view>
  55. </view>
  56. <NoData v-if="!useAppList.length" />
  57. </view>
  58. </view>
  59. </template>
  60. <script setup>
  61. import { ref } from 'vue'
  62. import { onLoad, onPageScroll, onPullDownRefresh, onShow } from '@dcloudio/uni-app'
  63. import { myRequest } from '@/utils/api.js'
  64. import NoData from '@/components/noData.vue'
  65. import { decryptDes } from '@/utils/des.js'
  66. onLoad(() => {
  67. // 获取系统信息
  68. uni.getSystemInfo({
  69. success: (e) => {
  70. // 获取状态栏高度
  71. statusBarH.value = e.statusBarHeight
  72. // // 获取菜单按钮栏高度
  73. let custom = uni.getMenuButtonBoundingClientRect()
  74. customBarH.value = custom.height
  75. }
  76. })
  77. userInfo.value = uni.getStorageSync('userInfo')
  78. if (userInfo.value.identityId == 1) {
  79. // 如果是家长身份获取绑定学生信息
  80. getChildMsg()
  81. }
  82. // 获取用户应用权限列表
  83. getUseAppList()
  84. uni.$on('updateObj', updateObj)
  85. })
  86. onShow(() => {
  87. // 获取身份码信息
  88. getQrcode()
  89. })
  90. // 页面下拉刷新回调
  91. onPullDownRefresh(() => {
  92. getQrcode()
  93. qrcodeRef.value.remake()
  94. if (userInfo.value.identityId == 1) {
  95. getChildMsg()
  96. }
  97. getUseAppList()
  98. setTimeout(() => {
  99. uni.stopPullDownRefresh()
  100. }, 1500)
  101. })
  102. onPageScroll((e) => {
  103. if (e.scrollTop > 70) {
  104. showHeader.value = true
  105. } else {
  106. showHeader.value = false
  107. }
  108. })
  109. // 用户信息
  110. const userInfo = ref({})
  111. // 绑定小孩信息
  112. const childMsgList = ref([])
  113. // 当前展示的小孩信息
  114. const currentChild = ref({})
  115. // 顶部导航栏显示隐藏控制
  116. const showHeader = ref(false)
  117. // 状态栏高度
  118. const statusBarH = ref(0)
  119. // 胶囊按钮栏高度
  120. const customBarH = ref(0)
  121. // 二维码元素引用标记
  122. const qrcodeRef = ref(null)
  123. // 全部应用列表数据
  124. const list = ref([
  125. {
  126. id: 3,
  127. title: '学生轨迹',
  128. path: '/pages/track/track'
  129. },
  130. {
  131. id: 7,
  132. title: '消息通知',
  133. path: '/pages/msgWarn/msgWarn'
  134. },
  135. {
  136. id: 8,
  137. title: '访客预约',
  138. path: '/pagesReservation/reservation/reservation'
  139. },
  140. {
  141. id: 10,
  142. title: '校园预警',
  143. path: '/pagesWarning/home/home'
  144. },
  145. {
  146. id: 11,
  147. title: '通讯录',
  148. path: '/pages/grade/grade'
  149. },
  150. {
  151. title: '能耗管理',
  152. path: '/pages/energy/energy'
  153. }
  154. ])
  155. // 展示的app列表
  156. const useAppList = ref([])
  157. // 二维码信息
  158. const QRCodeUrl = ref('')
  159. // 二维码自定义样式
  160. const options = {
  161. typeNumber: -1,
  162. foregroundImageBorderRadius: 5,
  163. foregroundImageSrc: '/static/images/school-logo.jpg'
  164. }
  165. // 获取身份码信息
  166. const getQrcode = async () => {
  167. const res = await myRequest({
  168. url: '/wanzai/api/smartQrcode/generateQrcode',
  169. data: {
  170. userId: uni.getStorageSync('userInfo').id
  171. }
  172. })
  173. // console.log(res)
  174. const result = JSON.parse(decryptDes(res.data))
  175. QRCodeUrl.value = result.qrcode
  176. }
  177. // 获取绑定小孩的信息
  178. const getChildMsg = async () => {
  179. const res = await myRequest({
  180. url: '/wanzai/api/smartUser/queryAffiliateUserById',
  181. data: {
  182. id: uni.getStorageSync('userInfo').id
  183. }
  184. })
  185. // console.log(res)
  186. const result = JSON.parse(decryptDes(res.data))
  187. childMsgList.value = result
  188. if (childMsgList.value.length) {
  189. currentChild.value = childMsgList.value[0]
  190. }
  191. }
  192. // 获取用户应用权限列表
  193. const getUseAppList = async () => {
  194. const res = await myRequest({
  195. url: '/wanzai/api/smartIdentity/queryIdentityApplyById',
  196. data: {
  197. id: uni.getStorageSync('userInfo').identityId
  198. }
  199. })
  200. // console.log(res)
  201. const result = JSON.parse(decryptDes(res.data))
  202. // console.log(result)
  203. useAppList.value = result
  204. }
  205. // 跳转页面函数
  206. const goPage = (url, item) => {
  207. if (item && item.category == '自建小程序') {
  208. uni.navigateToMiniProgram({
  209. appId: item.appid,
  210. path: item.path
  211. })
  212. return
  213. }
  214. if (item && item.category == '移动端H5') {
  215. uni.navigateTo({
  216. url: `/pages/web/web?url=${item.path}`
  217. })
  218. return
  219. }
  220. if (url === '/pages/track/track') {
  221. if (!currentChild.value.id) {
  222. uni.showToast({
  223. title: '请关联孩子后再查看轨迹',
  224. icon: 'none',
  225. mask: true
  226. })
  227. return
  228. }
  229. uni.navigateTo({
  230. url: `/pages/track/track?id=${currentChild.value.id}`
  231. })
  232. }
  233. if (url === '/pagesReservation/reservation/reservation') {
  234. if (userInfo.value.identityId == 1 && !currentChild.value.id) {
  235. uni.showToast({
  236. title: '请关联孩子后再开始预约',
  237. icon: 'none',
  238. mask: true
  239. })
  240. return
  241. }
  242. uni.setStorageSync('Tab-activeIndex', 0)
  243. }
  244. uni.navigateTo({
  245. url
  246. })
  247. }
  248. // 点击二维码时的回调
  249. const handleClickCode = () => {
  250. uni.navigateTo({
  251. url: `/pages/quickMark/quickMark?value=${QRCodeUrl.value}`
  252. })
  253. }
  254. const updateObj = (data) => {
  255. currentChild.value = data
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. .container {
  260. display: flex;
  261. flex-direction: column;
  262. padding: 0 20rpx;
  263. height: 100vh;
  264. overflow: hidden;
  265. background-color: #f1f6fe;
  266. // 自定义导航栏区域样式
  267. .tab {
  268. position: relative;
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. font-size: 34rpx;
  273. .tab_img {
  274. position: absolute;
  275. top: v-bind(statusBarH);
  276. left: 0;
  277. width: 62rpx;
  278. height: 62rpx;
  279. }
  280. }
  281. .tab2 {
  282. z-index: 999;
  283. position: fixed;
  284. top: 0;
  285. left: 0;
  286. right: 0;
  287. padding: 0 20rpx;
  288. font-size: 34rpx;
  289. text-align: center;
  290. background-color: #fff;
  291. }
  292. // 顶部图片区域样式
  293. .header {
  294. position: relative;
  295. margin-top: 35rpx;
  296. width: 710rpx;
  297. height: 369rpx;
  298. color: #fff;
  299. font-size: 36rpx;
  300. border-radius: 10rpx;
  301. .header_img {
  302. width: 100%;
  303. height: 100%;
  304. }
  305. .header_icon {
  306. position: absolute;
  307. top: 25rpx;
  308. left: 25rpx;
  309. width: 47rpx;
  310. height: 47rpx;
  311. border-radius: 50%;
  312. }
  313. .header_school {
  314. position: absolute;
  315. top: 18rpx;
  316. left: 81rpx;
  317. font-size: 40rpx;
  318. }
  319. .header_name {
  320. position: absolute;
  321. top: 243rpx;
  322. right: 145rpx;
  323. }
  324. .header_grade {
  325. position: absolute;
  326. top: 292rpx;
  327. right: 145rpx;
  328. }
  329. .header_code {
  330. position: absolute;
  331. top: 245rpx;
  332. right: 28rpx;
  333. display: flex;
  334. justify-content: center;
  335. align-items: center;
  336. width: 98rpx;
  337. height: 98rpx;
  338. border-radius: 10rpx;
  339. background-color: #fff;
  340. }
  341. }
  342. // 详细信息区域样式
  343. .body {
  344. height: calc(100vh - 550rpx);
  345. margin-top: 20rpx;
  346. .body_header {
  347. position: relative;
  348. width: 710rpx;
  349. height: 128rpx;
  350. .info_bg {
  351. position: absolute;
  352. z-index: 1;
  353. width: 100%;
  354. height: 100%;
  355. pointer-events: none;
  356. }
  357. .info_img {
  358. position: absolute;
  359. top: 20rpx;
  360. left: 20rpx;
  361. z-index: 1;
  362. width: 90rpx;
  363. height: 90rpx;
  364. border-radius: 50%;
  365. }
  366. .info_name {
  367. position: absolute;
  368. top: 15rpx;
  369. left: 132rpx;
  370. z-index: 1;
  371. font-size: 32rpx;
  372. font-weight: bold;
  373. }
  374. .info_detail {
  375. position: absolute;
  376. top: 64rpx;
  377. left: 132rpx;
  378. z-index: 1;
  379. width: 136rpx;
  380. height: 46rpx;
  381. line-height: 46rpx;
  382. text-align: center;
  383. font-size: 24rpx;
  384. color: #0061ff;
  385. border-radius: 5rpx;
  386. background-color: #ebf2ff;
  387. }
  388. .info_change {
  389. position: absolute;
  390. top: 48rpx;
  391. left: 393rpx;
  392. z-index: 1;
  393. font-size: 24rpx;
  394. color: #a6a6a6;
  395. }
  396. .info_no {
  397. position: absolute;
  398. top: 38rpx;
  399. left: 163rpx;
  400. z-index: 1;
  401. font-size: 30rpx;
  402. color: #a6a6a6;
  403. }
  404. .info_bind {
  405. position: absolute;
  406. top: 20rpx;
  407. right: 0;
  408. display: flex;
  409. justify-content: flex-end;
  410. align-items: center;
  411. padding-right: 25rpx;
  412. width: 300rpx;
  413. height: 102rpx;
  414. font-size: 28rpx;
  415. color: #0061ff;
  416. background-color: #e8f1ff;
  417. .bind_img {
  418. margin-right: 5rpx;
  419. width: 42rpx;
  420. height: 42rpx;
  421. }
  422. }
  423. }
  424. .body_list {
  425. max-height: calc(100vh - 790rpx);
  426. overflow-y: auto;
  427. box-sizing: border-box;
  428. padding: 30rpx 30rpx;
  429. display: grid;
  430. grid-template-columns: repeat(3, 1fr);
  431. grid-auto-rows: 240rpx;
  432. background-color: #fff;
  433. gap: 20rpx 10rpx;
  434. .list_box {
  435. display: flex;
  436. flex-direction: column;
  437. justify-content: space-evenly;
  438. align-items: center;
  439. font-size: 28rpx;
  440. overflow: hidden;
  441. .box_img {
  442. width: 120rpx;
  443. height: 120rpx;
  444. border-radius: 32rpx;
  445. }
  446. .box_text {
  447. width: 100%;
  448. text-align: center;
  449. overflow: hidden;
  450. text-overflow: ellipsis;
  451. white-space: nowrap;
  452. }
  453. }
  454. }
  455. }
  456. }
  457. </style>