index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <!-- 顶部信息栏 -->
  3. <view class="profile-header rounded-b-2xl bg-gradient-to-b from-blue-500 to-red-500 text-white py-6 px-4">
  4. <view class="flex items-center gap-10 justify-around">
  5. <!-- 头像 -->
  6. <view class="flex flex-col gap-2 w-5/12">
  7. <view class="w-120 h-120 rounded-full bg-gray-200 flex items-center justify-center mx-auto">
  8. <image class="w-full h-full" src="/static/my/avatar.png"></image>
  9. </view>
  10. <view class="text-lg font-semibold text-center">{{ isLoggedIn ? 'admin' : '游客' }}</view>
  11. </view>
  12. <!-- 个人信息 -->
  13. <view class="w-7/12">
  14. <view class="flex items-center mt-1" v-if="isLoggedIn">
  15. <view class="text-xs mr-1 w-36 h-36">
  16. <image class="w-full h-full" src="/static/my/phone.png"></image>
  17. </view>
  18. <text class="text-sm">15116297551</text>
  19. </view>
  20. <view v-if="!isLoggedIn">
  21. <text class="text-sm">请登录后查看信息</text>
  22. </view>
  23. <view v-if="isLoggedIn">
  24. 上次登录系统时间:
  25. </view>
  26. <view class="flex items-center mt-1" v-if="isLoggedIn">
  27. <view class="text-xs mr-1 w-36 h-36">
  28. <image class="w-full h-full" src="/static/my/shad.png"></image>
  29. </view>
  30. <text class="text-sm">2025-10-29 15:11:41</text>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 功能列表 -->
  36. <view class="profile-list bg-white">
  37. <view class="border-b border-gray-100 bg-#f3f8fd m-4 rounded-2">
  38. <view class="flex items-center py-4 px-4" :class="{ 'opacity-50': !isLoggedIn }" @click="isLoggedIn && toModifyPhone()">
  39. <view class="text-red-500 mr-2 w-36 h-36">
  40. <image class="w-full h-full" src="/static/my/telphone.png"></image>
  41. </view>
  42. <text class="flex-1">修改号码</text>
  43. <text class="text-gray-400">></text>
  44. </view>
  45. </view>
  46. <view class="border-b border-gray-100 bg-#f3f8fd m-4 rounded-2">
  47. <view class="flex items-center py-4 px-4 " :class="{ 'opacity-50': !isLoggedIn }" @click="isLoggedIn && toModifyPassword()">
  48. <view class="text-red-500 mr-2 w-36 h-36">
  49. <image class="w-full h-full" src="/static/my/lock.png"></image>
  50. </view>
  51. <text class="flex-1">修改密码</text>
  52. <text class="text-gray-400">></text>
  53. </view>
  54. </view>
  55. <view class="border-b border-gray-100 bg-#f3f8fd m-4 rounded-2">
  56. <view class="flex items-center py-4 px-4" :class="{ 'opacity-50': !isLoggedIn }" @click="isLoggedIn && toFeedback()">
  57. <view class="text-red-500 mr-2 w-36 h-36">
  58. <image class="w-full h-full" src="/static/my/feedback.png"></image>
  59. </view>
  60. <text class="flex-1">意见反馈</text>
  61. <text class="text-gray-400">></text>
  62. </view>
  63. </view>
  64. <view class="border-b border-gray-100 bg-#f3f8fd m-4 rounded-2">
  65. <view class="flex items-center py-4 px-4" :class="{ 'opacity-50': !isLoggedIn }" @click="isLoggedIn && toLogReport()">
  66. <view class="text-red-500 mr-2 w-36 h-36">
  67. <image class="w-full h-full" src="/static/my/log.png"></image>
  68. </view>
  69. <text class="flex-1">日志上报</text>
  70. <text class="text-gray-400">></text>
  71. </view>
  72. </view>
  73. <view class="border-b border-gray-100 bg-#f3f8fd m-4 rounded-2">
  74. <view class="flex items-center py-4 px-4" :class="{ 'opacity-50': !isLoggedIn }" @click="isLoggedIn && scanQRCode()">
  75. <view class="text-red-500 mr-2 w-36 h-36">
  76. <image class="w-full h-full" src="/static/my/scan.png"></image>
  77. </view>
  78. <text class="flex-1">扫一扫</text>
  79. <text class="text-gray-400">></text>
  80. </view>
  81. </view>
  82. <view class="border-b border-gray-100 bg-#f3f8fd m-4 rounded-2">
  83. <view class="flex items-center py-4 px-4" :class="{ 'opacity-50': !isLoggedIn }" @click="isLoggedIn && toDisclaimer()">
  84. <view class="text-red-500 mr-2 w-36 h-36">
  85. <image class="w-full h-full" src="/static/my/info.png"></image>
  86. </view>
  87. <text class="flex-1">免责申明1</text>
  88. <text class="text-gray-400">></text>
  89. </view>
  90. </view>
  91. <view class="border-b border-gray-100 bg-#f3f8fd m-4 rounded-2">
  92. <view class="flex items-center py-4 px-4" @click="toggleLoginStatus">
  93. <view class="text-red-500 mr-2 w-36 h-36">
  94. <image class="w-full h-full" :src="isLoggedIn ? '/static/my/logout.png' : '/static/my/login.png'"></image>
  95. </view>
  96. <text class="flex-1" :class="{ 'text-red-500': isLoggedIn }" @click="getLogin">{{ isLoggedIn ? '退出登录' : '立即登录' }}</text>
  97. <text class="text-gray-400">></text>
  98. </view>
  99. </view>
  100. <CustomTabBar :current="1" />
  101. </view>
  102. </template>
  103. <script setup lang="ts">
  104. import { login } from '@/api/user';
  105. import { ref, onMounted } from 'vue'
  106. import CustomTabBar from "@/components/CustomTabBar.vue";
  107. async function getLogin(){
  108. if(isLoggedIn.value == false){
  109. try {
  110. const res = await login({
  111. username: 'admin',
  112. password: 'admin123'
  113. });
  114. console.log('登录接口返回数据:', res); // 打印完整返回值
  115. // 增加空值判断,防止 res 或 res.token 不存在
  116. if (res && res.token) {
  117. // 登录成功,存储 Token
  118. uni.setStorageSync('token', res.token);
  119. uni.showToast({ title: '登录成功' });
  120. isLoggedIn.value = true; // 标记已登录
  121. } else {
  122. uni.showToast({ title: '登录成功但未获取到Token', icon: 'none' });
  123. console.warn('Token 缺失:', res);
  124. }
  125. } catch (err) {
  126. console.error('登录失败:', err);
  127. uni.showToast({ title: '登录失败:' + (err.msg || '网络错误'), icon: 'none' });
  128. }
  129. }
  130. }
  131. // 添加登录状态响应式变量
  132. const isLoggedIn = ref(true)
  133. // 模拟检查登录状态
  134. const checkLoginStatus = () => {
  135. // 这里应该检查实际的登录状态,比如检查是否有token等
  136. // 暂时从本地存储中检查登录状态
  137. const token = uni.getStorageSync('token')
  138. isLoggedIn.value = token
  139. }
  140. // 页面加载时检查登录状态
  141. onMounted(() => {
  142. checkLoginStatus()
  143. })
  144. // 切换登录状态
  145. const toggleLoginStatus = () => {
  146. if (isLoggedIn.value) {
  147. // 退出登录
  148. uni.showModal({
  149. title: '确认退出',
  150. content: '您确定要退出登录吗?',
  151. cancelText: '取消',
  152. confirmText: '确认',
  153. success: (res) => {
  154. if (res.confirm) {
  155. // 执行退出登录逻辑
  156. console.log('用户确认退出登录')
  157. // 清除用户信息(实际项目中这里应该清除token等)
  158. uni.clearStorageSync()
  159. // 更新登录状态
  160. isLoggedIn.value = false
  161. uni.showToast({
  162. title: '已退出登录',
  163. icon: 'none'
  164. })
  165. } else {
  166. console.log('用户取消退出登录')
  167. }
  168. }
  169. })
  170. } else {
  171. // 登录方法(模拟)
  172. // 这里应该调用实际的登录接口
  173. // 模拟登录成功
  174. uni.setStorageSync('token', 'fake-token')
  175. isLoggedIn.value = true
  176. uni.showToast({
  177. title: '登录成功',
  178. icon: 'success'
  179. })
  180. }
  181. }
  182. const toModifyPhone = () => {
  183. uni.navigateTo({
  184. url: '/pages/modify-phone/index',
  185. animationType:'slide-in-right',
  186. animationDuration:300
  187. })
  188. }
  189. const toModifyPassword = () => {
  190. uni.navigateTo({
  191. url: '/pages/modify-password/index',
  192. animationType:'slide-in-right',
  193. animationDuration:300
  194. })
  195. }
  196. const toFeedback = () => {
  197. uni.navigateTo({
  198. url: '/pages/feedback/index',
  199. animationType:'slide-in-right',
  200. animationDuration:300
  201. })
  202. }
  203. const toLogReport = () => {
  204. uni.navigateTo({
  205. url: '/pages/log-report/index',
  206. animationType:'slide-in-right',
  207. animationDuration:300
  208. })
  209. }
  210. // 扫一扫功能
  211. const scanQRCode = () => {
  212. uni.scanCode({
  213. success: (res) => {
  214. console.log('扫描结果:', res);
  215. uni.showModal({
  216. title: '扫描结果',
  217. content: res.result,
  218. showCancel: false,
  219. confirmText: '确定'
  220. });
  221. },
  222. fail: (err) => {
  223. console.error('扫描失败:', err);
  224. uni.showToast({
  225. title: '扫描失败,请重试',
  226. icon: 'error'
  227. });
  228. }
  229. });
  230. }
  231. // 跳转到免责申明页面
  232. const toDisclaimer = () => {
  233. uni.navigateTo({
  234. url: '/pages/disclaimer/index',
  235. animationType:'slide-in-right',
  236. animationDuration:300
  237. })
  238. }
  239. </script>