home.vue 10 KB

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