home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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 (userInfo.value.identityId == 1) {
  218. if (!currentChild.value.id) {
  219. uni.showToast({
  220. title: '请关联孩子后再查看轨迹',
  221. icon: 'none',
  222. mask: true
  223. })
  224. return
  225. }
  226. uni.navigateTo({
  227. url: `/pages/track/track?id=${currentChild.value.id}`
  228. })
  229. return
  230. } else {
  231. uni.navigateTo({
  232. url: '/pages/grade/grade?type=学生轨迹'
  233. })
  234. return
  235. }
  236. }
  237. if (url === '/pagesReservation/reservation/reservation') {
  238. if (userInfo.value.identityId == 1 && !currentChild.value.id) {
  239. uni.showToast({
  240. title: '请关联孩子后再开始预约',
  241. icon: 'none',
  242. mask: true
  243. })
  244. return
  245. }
  246. uni.setStorageSync('Tab-activeIndex', 0)
  247. }
  248. uni.navigateTo({
  249. url
  250. })
  251. }
  252. // 点击二维码时的回调
  253. const handleClickCode = () => {
  254. uni.navigateTo({
  255. url: `/pages/quickMark/quickMark?value=${QRCodeUrl.value}`
  256. })
  257. }
  258. const updateObj = (data) => {
  259. currentChild.value = data
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. .container {
  264. display: flex;
  265. flex-direction: column;
  266. padding: 0 20rpx;
  267. min-height: 100vh;
  268. background-color: #f1f6fe;
  269. // 自定义导航栏区域样式
  270. .tab {
  271. position: relative;
  272. display: flex;
  273. justify-content: center;
  274. align-items: center;
  275. font-size: 34rpx;
  276. .tab_img {
  277. position: absolute;
  278. top: v-bind(statusBarH);
  279. left: 0;
  280. width: 62rpx;
  281. height: 62rpx;
  282. }
  283. }
  284. .tab2 {
  285. z-index: 999;
  286. position: fixed;
  287. top: 0;
  288. left: 0;
  289. right: 0;
  290. padding: 0 20rpx;
  291. font-size: 34rpx;
  292. text-align: center;
  293. background-color: #fff;
  294. }
  295. // 顶部图片区域样式
  296. .header {
  297. position: relative;
  298. margin-top: 35rpx;
  299. width: 710rpx;
  300. height: 369rpx;
  301. color: #fff;
  302. font-size: 36rpx;
  303. border-radius: 10rpx;
  304. .header_img {
  305. width: 100%;
  306. height: 100%;
  307. }
  308. .header_icon {
  309. position: absolute;
  310. top: 25rpx;
  311. left: 25rpx;
  312. width: 47rpx;
  313. height: 47rpx;
  314. border-radius: 50%;
  315. }
  316. .header_school {
  317. position: absolute;
  318. top: 18rpx;
  319. left: 81rpx;
  320. font-size: 40rpx;
  321. }
  322. .header_name {
  323. position: absolute;
  324. top: 243rpx;
  325. right: 145rpx;
  326. }
  327. .header_grade {
  328. position: absolute;
  329. top: 292rpx;
  330. right: 145rpx;
  331. }
  332. .header_code {
  333. position: absolute;
  334. top: 245rpx;
  335. right: 28rpx;
  336. display: flex;
  337. justify-content: center;
  338. align-items: center;
  339. width: 98rpx;
  340. height: 98rpx;
  341. border-radius: 10rpx;
  342. background-color: #fff;
  343. }
  344. }
  345. // 详细信息区域样式
  346. .body {
  347. margin-top: 20rpx;
  348. .body_header {
  349. position: relative;
  350. width: 710rpx;
  351. height: 128rpx;
  352. .info_bg {
  353. position: absolute;
  354. z-index: 1;
  355. width: 100%;
  356. height: 100%;
  357. pointer-events: none;
  358. }
  359. .info_img {
  360. position: absolute;
  361. top: 20rpx;
  362. left: 20rpx;
  363. z-index: 1;
  364. width: 90rpx;
  365. height: 90rpx;
  366. border-radius: 50%;
  367. }
  368. .info_name {
  369. position: absolute;
  370. top: 15rpx;
  371. left: 132rpx;
  372. z-index: 1;
  373. font-size: 32rpx;
  374. font-weight: bold;
  375. }
  376. .info_detail {
  377. position: absolute;
  378. top: 64rpx;
  379. left: 132rpx;
  380. z-index: 1;
  381. width: 136rpx;
  382. height: 46rpx;
  383. line-height: 46rpx;
  384. text-align: center;
  385. font-size: 24rpx;
  386. color: #0061ff;
  387. border-radius: 5rpx;
  388. background-color: #ebf2ff;
  389. }
  390. .info_change {
  391. position: absolute;
  392. top: 48rpx;
  393. left: 393rpx;
  394. z-index: 1;
  395. font-size: 24rpx;
  396. color: #a6a6a6;
  397. }
  398. .info_no {
  399. position: absolute;
  400. top: 38rpx;
  401. left: 163rpx;
  402. z-index: 1;
  403. font-size: 30rpx;
  404. color: #a6a6a6;
  405. }
  406. .info_bind {
  407. position: absolute;
  408. top: 20rpx;
  409. right: 0;
  410. display: flex;
  411. justify-content: flex-end;
  412. align-items: center;
  413. padding-right: 25rpx;
  414. width: 300rpx;
  415. height: 102rpx;
  416. font-size: 28rpx;
  417. color: #0061ff;
  418. background-color: #e8f1ff;
  419. .bind_img {
  420. margin-right: 5rpx;
  421. width: 42rpx;
  422. height: 42rpx;
  423. }
  424. }
  425. }
  426. .body_list {
  427. padding: 30rpx 30rpx;
  428. display: grid;
  429. grid-template-columns: repeat(3, 1fr);
  430. grid-auto-rows: 240rpx;
  431. background-color: #fff;
  432. gap: 20rpx 10rpx;
  433. .list_box {
  434. display: flex;
  435. flex-direction: column;
  436. justify-content: space-evenly;
  437. align-items: center;
  438. font-size: 28rpx;
  439. overflow: hidden;
  440. .box_img {
  441. width: 120rpx;
  442. height: 120rpx;
  443. border-radius: 32rpx;
  444. }
  445. .box_text {
  446. width: 100%;
  447. text-align: center;
  448. overflow: hidden;
  449. text-overflow: ellipsis;
  450. white-space: nowrap;
  451. }
  452. }
  453. }
  454. }
  455. }
  456. </style>