index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <hc-sys class="hc-user-page" :tabbar="false" :isNavBar="false">
  3. <hc-nav-bar class="user-nav-bar" :style="`background: rgba(85, 77, 132, ${opacitys})`">
  4. <text class="i-ri-settings-4-fill" @click="toSkipClick('/pages/my/config')"/>
  5. </hc-nav-bar>
  6. <view class="user-nav-bg"/>
  7. <!--内容区域-->
  8. <view class="hc-user-content-box">
  9. <view class="user-nav-h"/>
  10. <!--个人信息卡片-->
  11. <view class="user-info-card animation-mode" :class="isAnimation?'is-animation':''">
  12. <view class="name-avatar-bar">
  13. <view class="name" @click="toSkipClick('/pages/my/info')">{{userInfo.realName}}</view>
  14. <view class="avatar" @click="selectImageTap">
  15. <HcImg class="avatar-img" :src="userInfo.avatar" width="72" height="72"/>
  16. </view>
  17. </view>
  18. <view class="user-auth-bar">
  19. <view class="auth-tag visit">
  20. <text class="i-ri-vip-diamond-line"/>
  21. <text class="name">{{userInfo.roleName}}</text>
  22. </view>
  23. <view class="auth-tag approve">
  24. <text class="name">审批权限</text>
  25. <text class="i-ri-checkbox-circle-fill check-icon" v-if="userInfo.signatureUrl"/>
  26. <text class="i-ri-close-circle-fill close-icon" v-else/>
  27. </view>
  28. </view>
  29. <uni-row class="info-num-bar">
  30. <uni-col :span="8" class="col-bar">
  31. <view class="num">{{userInfo.fillNum}}</view>
  32. <view class="text">填报数量</view>
  33. </uni-col>
  34. <uni-col :span="8" class="col-bar">
  35. <view class="num">{{userInfo.appdNum}}</view>
  36. <view class="text">审批数量</view>
  37. </uni-col>
  38. <uni-col :span="8" class="col-bar">
  39. <view class="num">{{userInfo.fbNum}}</view>
  40. <view class="text">反馈问题</view>
  41. </uni-col>
  42. </uni-row>
  43. </view>
  44. <!--常用操作-->
  45. <view class="common-operation-box">
  46. <view class="title">常用操作</view>
  47. <uni-row :gutter="24" class="handle-row-bar">
  48. <uni-col :span="12">
  49. <view class="col-item-card animation-mode"
  50. :class="isAnimation?'in-left':''"
  51. @click="toSkipClick('/pages/my/project')"
  52. >
  53. <view class="content">
  54. <view class="title">项目管理</view>
  55. <view class="text">设置当前默认项目</view>
  56. </view>
  57. <view class="icon-bar">
  58. <text class="i-ri-stack-line"/>
  59. </view>
  60. </view>
  61. </uni-col>
  62. <uni-col :span="12" class="col-bar">
  63. <view class="col-item-card animation-mode"
  64. :class="isAnimation?'in-right':''"
  65. @click="toSkipClick('/pages/my/record')"
  66. >
  67. <view class="content">
  68. <view class="title">填报记录</view>
  69. <view class="text">查看历史记录</view>
  70. </view>
  71. <view class="icon-bar">
  72. <text class="i-ri-file-history-line"/>
  73. </view>
  74. </view>
  75. </uni-col>
  76. </uni-row>
  77. <uni-row :gutter="24" class="handle-row-bar">
  78. <uni-col :span="12">
  79. <view class="col-item-card animation-mode"
  80. :class="isAnimation?'in-left':''"
  81. @click="toSkipClick('/pages/my/explain')"
  82. >
  83. <view class="content">
  84. <view class="title">相关资料</view>
  85. <view class="text">查看系统相关资料</view>
  86. </view>
  87. <view class="icon-bar">
  88. <text class="i-ri-profile-line"/>
  89. </view>
  90. </view>
  91. </uni-col>
  92. <uni-col :span="12" class="col-bar">
  93. <view class="col-item-card animation-mode"
  94. :class="isAnimation?'in-right':''"
  95. @click="toSkipClick('/pages/my/customer')"
  96. >
  97. <view class="content">
  98. <view class="title">我的客服</view>
  99. <view class="text">问题反馈寻求帮助</view>
  100. </view>
  101. <view class="icon-bar">
  102. <text class="i-ri-question-answer-line"/>
  103. </view>
  104. </view>
  105. </uni-col>
  106. </uni-row>
  107. </view>
  108. <!--消息动态-->
  109. <view class="news-dynamics-box animation-mode"
  110. :class="isAnimation?'is-animation':''"
  111. @click="toSkipClick('/pages/work-order/index')"
  112. >
  113. <view class="title-bar">
  114. <text class="i-ri-notification-2-fill"/>
  115. <text class="name">消息动态圈</text>
  116. </view>
  117. </view>
  118. <!--退出按钮-->
  119. <view class="exit-button-bar" :class="isAnimation?'is-animation':''">
  120. <button class="exit-button animation-mode" @click="signOutClick">退出登录</button>
  121. </view>
  122. </view>
  123. </hc-sys>
  124. </template>
  125. <script setup>
  126. import {ref} from "vue";
  127. import mainApi from '~api/user/index';
  128. import {onShow, onHide, onPageScroll} from '@dcloudio/uni-app'
  129. import {errorToast, successToast} from "@/utils/tools";
  130. import {getTokenHeader} from "@/httpApi/request/header";
  131. import {getObjValue} from "js-fast-way";
  132. import {getUploadApi} from "@/httpApi/modules/upload";
  133. import {useAppStore} from "@/store";
  134. //初始变量
  135. const store = useAppStore()
  136. const userInfo = ref(store.userInfo);
  137. //获取数据
  138. const setUserData = async () => {
  139. const user_info = userInfo.value
  140. const user = await mainApi.queryCurrentUserData()
  141. const yown = await mainApi.appQuerYownData()
  142. userInfo.value = {
  143. ...user_info,
  144. ...getObjValue(user.data),
  145. ...getObjValue(yown.data),
  146. }
  147. }
  148. const isAnimation = ref(store.isAnimation)
  149. onShow(()=>{
  150. setUserData()
  151. if(store.isAnimation) {
  152. isAnimation.value = true
  153. }
  154. })
  155. onHide(() => {
  156. isAnimation.value = false
  157. })
  158. //选择头像
  159. const selectImageTap = () => {
  160. uni.chooseImage({
  161. count: 1,
  162. sizeType: ['original'],
  163. success: (res)=> {
  164. uploadAvatarFile(res.tempFilePaths[0])
  165. }
  166. });
  167. }
  168. //上传头像文件
  169. const uploadAvatarFile = async (file) => {
  170. uni.showLoading({title: '上传头像中...', mask: true});
  171. const url = await uploadFile(file)
  172. if(!url) {
  173. uni.hideLoading();
  174. return;
  175. }
  176. const {user_id} = userInfo.value
  177. const {error, code} = await mainApi.updateUserInfo({
  178. avatar: url,
  179. id: user_id
  180. })
  181. if (!error && code === 200) {
  182. userInfo.value.avatar = url
  183. store.setUserInfo(userInfo.value)
  184. uni.hideLoading();
  185. successToast('头像上传成功')
  186. } else {
  187. uni.hideLoading();
  188. errorToast('头像上传失败');
  189. }
  190. }
  191. //上传文件
  192. const uploadFile = async (file) => {
  193. return new Promise((resolve) => {
  194. uni.uploadFile({
  195. url: getUploadApi() + 'blade-resource/oss/endpoint/put-file',
  196. name: 'file',
  197. filePath: file,
  198. header: getTokenHeader(),
  199. timeout: 300000,
  200. success: (res) => {
  201. const data = JSON.parse(res.data)
  202. const {link} = getObjValue(data.data)
  203. if (!link) errorToast('文件上传异常');
  204. resolve(link ?? '');
  205. },
  206. fail: () => {
  207. errorToast('文件上传失败');
  208. resolve('');
  209. }
  210. });
  211. })
  212. }
  213. //跳转到其他页面
  214. const toSkipClick = (url) => {
  215. uni.navigateTo({url: url});
  216. }
  217. //退出登录
  218. const signOutClick = () => {
  219. uni.reLaunch({url: '/pages/login/login'});
  220. }
  221. //监听页面滚动
  222. const opacitys = ref(0)
  223. onPageScroll((event) => {
  224. const scrollTop = event.scrollTop
  225. if (scrollTop <= 1) {
  226. opacitys.value = 0
  227. } else if (scrollTop > 1 && scrollTop <= 10) {
  228. opacitys.value = 0.2
  229. } else if (scrollTop > 10 && scrollTop <= 20) {
  230. opacitys.value = 0.4
  231. } else if (scrollTop > 20 && scrollTop <= 30) {
  232. opacitys.value = 0.6
  233. } else if (scrollTop > 30 && scrollTop <= 40) {
  234. opacitys.value = 0.8
  235. } else if (scrollTop > 40) {
  236. opacitys.value = 1
  237. }
  238. })
  239. </script>
  240. <style lang="scss">
  241. @import "@/style/my/index.scss";
  242. </style>