home.vue 11 KB

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