home.vue 9.6 KB

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