home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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. // 展示的app列表
  152. const useAppList = ref([])
  153. // 二维码信息
  154. const QRCodeUrl = ref('')
  155. // 二维码自定义样式
  156. const options = {
  157. typeNumber: -1,
  158. foregroundImageBorderRadius: 5,
  159. foregroundImageSrc: '/static/images/school-logo.jpg'
  160. }
  161. // 获取身份码信息
  162. const getQrcode = async () => {
  163. const res = await myRequest({
  164. url: '/wanzai/api/smartQrcode/generateQrcode',
  165. data: {
  166. userId: uni.getStorageSync('userInfo').id
  167. }
  168. })
  169. // console.log(res)
  170. const result = JSON.parse(decryptDes(res.data))
  171. QRCodeUrl.value = result.qrcode
  172. }
  173. // 获取绑定小孩的信息
  174. const getChildMsg = async () => {
  175. const res = await myRequest({
  176. url: '/wanzai/api/smartUser/queryAffiliateUserById',
  177. data: {
  178. id: uni.getStorageSync('userInfo').id
  179. }
  180. })
  181. // console.log(res)
  182. const result = JSON.parse(decryptDes(res.data))
  183. childMsgList.value = result
  184. if (childMsgList.value.length) {
  185. currentChild.value = childMsgList.value[0]
  186. }
  187. }
  188. // 获取用户应用权限列表
  189. const getUseAppList = async () => {
  190. const res = await myRequest({
  191. url: '/wanzai/api/smartIdentity/queryIdentityApplyById',
  192. data: {
  193. id: uni.getStorageSync('userInfo').identityId
  194. }
  195. })
  196. // console.log(res)
  197. const result = JSON.parse(decryptDes(res.data))
  198. // console.log(result)
  199. useAppList.value = result
  200. }
  201. // 跳转页面函数
  202. const goPage = (url, item) => {
  203. if (item && item.category == '其他小程序') {
  204. uni.navigateToMiniProgram({
  205. appId: item.appid,
  206. path: item.path
  207. })
  208. return
  209. }
  210. if (item && item.category == '移动端H5') {
  211. uni.navigateTo({
  212. url: `/pages/web/web?url=${item.path}`
  213. })
  214. return
  215. }
  216. if (url === '/pages/track/track') {
  217. if (!currentChild.value.id) {
  218. uni.showToast({
  219. title: '请关联孩子后再查看轨迹',
  220. icon: 'none',
  221. mask: true
  222. })
  223. return
  224. }
  225. uni.navigateTo({
  226. url: `/pages/track/track?id=${currentChild.value.id}`
  227. })
  228. }
  229. if (url === '/pagesReservation/reservation/reservation') {
  230. if (userInfo.value.identityId == 1 && !currentChild.value.id) {
  231. uni.showToast({
  232. title: '请关联孩子后再开始预约',
  233. icon: 'none',
  234. mask: true
  235. })
  236. return
  237. }
  238. uni.setStorageSync('Tab-activeIndex', 0)
  239. }
  240. uni.navigateTo({
  241. url
  242. })
  243. }
  244. // 点击二维码时的回调
  245. const handleClickCode = () => {
  246. uni.navigateTo({
  247. url: `/pages/quickMark/quickMark?value=${QRCodeUrl.value}`
  248. })
  249. }
  250. const updateObj = (data) => {
  251. currentChild.value = data
  252. }
  253. </script>
  254. <style lang="scss" scoped>
  255. .container {
  256. display: flex;
  257. flex-direction: column;
  258. padding: 0 20rpx;
  259. height: 100vh;
  260. overflow: hidden;
  261. background-color: #f1f6fe;
  262. // 自定义导航栏区域样式
  263. .tab {
  264. position: relative;
  265. display: flex;
  266. justify-content: center;
  267. align-items: center;
  268. font-size: 34rpx;
  269. .tab_img {
  270. position: absolute;
  271. top: v-bind(statusBarH);
  272. left: 0;
  273. width: 62rpx;
  274. height: 62rpx;
  275. }
  276. }
  277. .tab2 {
  278. z-index: 999;
  279. position: fixed;
  280. top: 0;
  281. left: 0;
  282. right: 0;
  283. padding: 0 20rpx;
  284. font-size: 34rpx;
  285. text-align: center;
  286. background-color: #fff;
  287. }
  288. // 顶部图片区域样式
  289. .header {
  290. position: relative;
  291. margin-top: 35rpx;
  292. width: 710rpx;
  293. height: 369rpx;
  294. color: #fff;
  295. font-size: 36rpx;
  296. border-radius: 10rpx;
  297. .header_img {
  298. width: 100%;
  299. height: 100%;
  300. }
  301. .header_icon {
  302. position: absolute;
  303. top: 25rpx;
  304. left: 25rpx;
  305. width: 47rpx;
  306. height: 47rpx;
  307. border-radius: 50%;
  308. }
  309. .header_school {
  310. position: absolute;
  311. top: 18rpx;
  312. left: 81rpx;
  313. font-size: 40rpx;
  314. }
  315. .header_name {
  316. position: absolute;
  317. top: 243rpx;
  318. right: 145rpx;
  319. }
  320. .header_grade {
  321. position: absolute;
  322. top: 292rpx;
  323. right: 145rpx;
  324. }
  325. .header_code {
  326. position: absolute;
  327. top: 245rpx;
  328. right: 28rpx;
  329. display: flex;
  330. justify-content: center;
  331. align-items: center;
  332. width: 98rpx;
  333. height: 98rpx;
  334. border-radius: 10rpx;
  335. background-color: #fff;
  336. }
  337. }
  338. // 详细信息区域样式
  339. .body {
  340. height: calc(100vh - 550rpx);
  341. margin-top: 20rpx;
  342. .body_header {
  343. position: relative;
  344. width: 710rpx;
  345. height: 128rpx;
  346. .info_bg {
  347. position: absolute;
  348. z-index: 1;
  349. width: 100%;
  350. height: 100%;
  351. pointer-events: none;
  352. }
  353. .info_img {
  354. position: absolute;
  355. top: 20rpx;
  356. left: 20rpx;
  357. z-index: 1;
  358. width: 90rpx;
  359. height: 90rpx;
  360. border-radius: 50%;
  361. }
  362. .info_name {
  363. position: absolute;
  364. top: 15rpx;
  365. left: 132rpx;
  366. z-index: 1;
  367. font-size: 32rpx;
  368. font-weight: bold;
  369. }
  370. .info_detail {
  371. position: absolute;
  372. top: 64rpx;
  373. left: 132rpx;
  374. z-index: 1;
  375. width: 136rpx;
  376. height: 46rpx;
  377. line-height: 46rpx;
  378. text-align: center;
  379. font-size: 24rpx;
  380. color: #0061ff;
  381. border-radius: 5rpx;
  382. background-color: #ebf2ff;
  383. }
  384. .info_change {
  385. position: absolute;
  386. top: 48rpx;
  387. left: 393rpx;
  388. z-index: 1;
  389. font-size: 24rpx;
  390. color: #a6a6a6;
  391. }
  392. .info_no {
  393. position: absolute;
  394. top: 38rpx;
  395. left: 163rpx;
  396. z-index: 1;
  397. font-size: 30rpx;
  398. color: #a6a6a6;
  399. }
  400. .info_bind {
  401. position: absolute;
  402. top: 20rpx;
  403. right: 0;
  404. display: flex;
  405. justify-content: flex-end;
  406. align-items: center;
  407. padding-right: 25rpx;
  408. width: 300rpx;
  409. height: 102rpx;
  410. font-size: 28rpx;
  411. color: #0061ff;
  412. background-color: #e8f1ff;
  413. .bind_img {
  414. margin-right: 5rpx;
  415. width: 42rpx;
  416. height: 42rpx;
  417. }
  418. }
  419. }
  420. .body_list {
  421. max-height: calc(100vh - 790rpx);
  422. overflow-y: auto;
  423. box-sizing: border-box;
  424. padding: 30rpx 30rpx;
  425. display: grid;
  426. grid-template-columns: repeat(3, 1fr);
  427. grid-auto-rows: 240rpx;
  428. background-color: #fff;
  429. gap: 20rpx 10rpx;
  430. .list_box {
  431. display: flex;
  432. flex-direction: column;
  433. justify-content: space-evenly;
  434. align-items: center;
  435. font-size: 28rpx;
  436. overflow: hidden;
  437. .box_img {
  438. width: 120rpx;
  439. height: 120rpx;
  440. border-radius: 32rpx;
  441. }
  442. .box_text {
  443. width: 100%;
  444. text-align: center;
  445. overflow: hidden;
  446. text-overflow: ellipsis;
  447. white-space: nowrap;
  448. }
  449. }
  450. }
  451. }
  452. }
  453. </style>