home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. useAppList.value = result
  198. }
  199. // 跳转页面函数
  200. const goPage = (url, item) => {
  201. if (item && item.category == '其他小程序') {
  202. uni.navigateToMiniProgram({
  203. appId: item.appid,
  204. path: item.path
  205. })
  206. return
  207. }
  208. if (item && item.category == '移动端H5') {
  209. uni.navigateTo({
  210. url: `/pages/web/web?url=${item.path}`
  211. })
  212. return
  213. }
  214. if (url === '/pages/track/track') {
  215. if (userInfo.value.identityId == 1) {
  216. if (!currentChild.value.id) {
  217. uni.showToast({
  218. title: '请关联孩子后再查看轨迹',
  219. icon: 'none',
  220. mask: true
  221. })
  222. return
  223. }
  224. uni.navigateTo({
  225. url: `/pages/track/track?id=${currentChild.value.id}`
  226. })
  227. return
  228. } else {
  229. uni.navigateTo({
  230. url: '/pages/grade/grade?type=学生轨迹'
  231. })
  232. return
  233. }
  234. }
  235. if (url === '/pagesReservation/reservation/reservation') {
  236. if (userInfo.value.identityId == 1 && !currentChild.value.id) {
  237. uni.showToast({
  238. title: '请关联孩子后再开始预约',
  239. icon: 'none',
  240. mask: true
  241. })
  242. return
  243. }
  244. uni.setStorageSync('Tab-activeIndex', 0)
  245. }
  246. uni.navigateTo({
  247. url
  248. })
  249. }
  250. // 点击二维码时的回调
  251. const handleClickCode = () => {
  252. uni.navigateTo({
  253. url: `/pages/quickMark/quickMark?value=${QRCodeUrl.value}`
  254. })
  255. }
  256. const updateObj = (data) => {
  257. currentChild.value = data
  258. }
  259. </script>
  260. <style lang="scss" scoped>
  261. .container {
  262. display: flex;
  263. flex-direction: column;
  264. padding: 0 20rpx;
  265. min-height: 100vh;
  266. background-color: #f1f6fe;
  267. // 自定义导航栏区域样式
  268. .tab {
  269. position: relative;
  270. display: flex;
  271. justify-content: center;
  272. align-items: center;
  273. font-size: 34rpx;
  274. .tab_img {
  275. position: absolute;
  276. top: v-bind(statusBarH);
  277. left: 0;
  278. width: 62rpx;
  279. height: 62rpx;
  280. }
  281. }
  282. .tab2 {
  283. z-index: 999;
  284. position: fixed;
  285. top: 0;
  286. left: 0;
  287. right: 0;
  288. padding: 0 20rpx;
  289. font-size: 34rpx;
  290. text-align: center;
  291. background-color: #fff;
  292. }
  293. // 顶部图片区域样式
  294. .header {
  295. position: relative;
  296. margin-top: 35rpx;
  297. width: 710rpx;
  298. height: 369rpx;
  299. color: #fff;
  300. font-size: 36rpx;
  301. border-radius: 10rpx;
  302. .header_img {
  303. width: 100%;
  304. height: 100%;
  305. }
  306. .header_icon {
  307. position: absolute;
  308. top: 25rpx;
  309. left: 25rpx;
  310. width: 47rpx;
  311. height: 47rpx;
  312. border-radius: 50%;
  313. }
  314. .header_school {
  315. position: absolute;
  316. top: 18rpx;
  317. left: 81rpx;
  318. font-size: 40rpx;
  319. }
  320. .header_name {
  321. position: absolute;
  322. top: 243rpx;
  323. right: 145rpx;
  324. }
  325. .header_grade {
  326. position: absolute;
  327. top: 292rpx;
  328. right: 145rpx;
  329. }
  330. .header_code {
  331. position: absolute;
  332. top: 245rpx;
  333. right: 28rpx;
  334. display: flex;
  335. justify-content: center;
  336. align-items: center;
  337. width: 98rpx;
  338. height: 98rpx;
  339. border-radius: 10rpx;
  340. background-color: #fff;
  341. }
  342. }
  343. // 详细信息区域样式
  344. .body {
  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. padding: 30rpx 30rpx;
  426. display: grid;
  427. grid-template-columns: repeat(3, 1fr);
  428. grid-auto-rows: 240rpx;
  429. background-color: #fff;
  430. gap: 20rpx 10rpx;
  431. .list_box {
  432. display: flex;
  433. flex-direction: column;
  434. justify-content: space-evenly;
  435. align-items: center;
  436. font-size: 28rpx;
  437. overflow: hidden;
  438. .box_img {
  439. width: 120rpx;
  440. height: 120rpx;
  441. border-radius: 32rpx;
  442. }
  443. .box_text {
  444. width: 100%;
  445. text-align: center;
  446. overflow: hidden;
  447. text-overflow: ellipsis;
  448. white-space: nowrap;
  449. }
  450. }
  451. }
  452. }
  453. }
  454. </style>