index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <z-paging ref="paging" v-model="list" @query="queryList" @onRefresh="onRefresh">
  3. <template #top>
  4. <!-- 用户信息区域 -->
  5. <view class="user-info-section">
  6. <view v-if="userInfo" class="user-card">
  7. <image :src="userInfo.avatar || '/static/logo.png'" class="user-avatar" />
  8. <view class="user-details">
  9. <text class="user-name">{{ userInfo.nickname || userInfo.username }}</text>
  10. <text class="user-roles">{{ userInfo.roles.join(', ') }}</text>
  11. </view>
  12. <button class="logout-btn" @click="handleLogout">退出登录</button>
  13. </view>
  14. <view v-else class="login-prompt">
  15. <text class="prompt-text">请先登录111</text>
  16. <button class="login-btn" @click="goToLogin">前往登录123</button>
  17. </view>
  18. </view>
  19. </template>
  20. <view class="content">
  21. <image class="logo" src="/static/logo.png" />
  22. <view class="text-area">
  23. <text class="title">{{ title }}</text>
  24. </view>
  25. <!-- <view class="mb-80">{{ selectDictLabel(class_type, 1) }}</view> -->
  26. <view class="bg-blue-500 c-primary p-4 rounded">Hello UnoCSS!</view>
  27. <up-button @click="$u.route({ type: 'switchTab', url: '/pages/plant/base/index' })" text="index1" color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))" />
  28. <up-button @click="$u.route({ type: 'switchTab', url: '/pages/plant/port/index' })" text="plantport" color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))" />
  29. <up-button @click="$u.route({ type: 'navigateTo', url: '/pages/plant/base/index' })" text="plant" color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))" />
  30. <up-button @click="$u.route({ type: 'switchTab', url: '/pages/production/index' })" text="production" color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))" />
  31. </view>
  32. </z-paging>
  33. </template>
  34. <script setup lang="ts">
  35. import { computed } from 'vue';
  36. import { useAuthStore } from '@/store/modules/auth';
  37. import { useUserStore } from '@/store/modules/user';
  38. import { checkAuth, logoutAndRedirect } from '@/utils/routeGuard';
  39. // const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  40. // const { class_type } = toRefs<any>(proxy?.useDict('class_type'));
  41. const title = ref('Hello');
  42. const paging = ref<any>(null);
  43. // Store
  44. const authStore = useAuthStore();
  45. const userStore = useUserStore();
  46. // 计算属性
  47. const userInfo = computed(() => userStore.userInfo);
  48. console.log(import.meta.env);
  49. onMounted(async () => {
  50. // 检查登录状态
  51. await checkAuth({ requireAuth: false });
  52. uni.showToast({
  53. title: 'Hello World!',
  54. icon: 'none',
  55. duration: 2000,
  56. });
  57. });
  58. const list = ref<any[]>([]);
  59. const queryList = (pageNo: number, pageSize: number) => {
  60. console.log(`请求第${pageNo}页,每页${pageSize}条数据`);
  61. // 这里的pageNo和pageSize会自动计算好,直接传给服务器即可
  62. // 这里的请求只是演示,请替换成自己的项目的网络请求,并在网络请求回调中通过paging.value.complete(请求回来的数组)将请求结果传给z-paging
  63. setTimeout(() => {
  64. const data = Array.from({ length: pageSize }, (_, i) => ({
  65. id: pageNo * pageSize + i + 1,
  66. name: `Item ${pageNo * pageSize + i + 1}`,
  67. }));
  68. paging.value.complete(data);
  69. }, 1000);
  70. };
  71. const onRefresh = () => {
  72. try {
  73. // 这里可以执行一些刷新操作,比如重新请求数据
  74. console.log('页面刷新');
  75. paging.value.refresh(); // 调用z-paging的refresh方法
  76. } catch (error) {
  77. console.error('刷新失败', error);
  78. }
  79. };
  80. /**
  81. * 前往登录页
  82. */
  83. const goToLogin = (): void => {
  84. uni.navigateTo({
  85. url: '/pages/login/login',
  86. });
  87. };
  88. /**
  89. * 处理退出登录
  90. */
  91. const handleLogout = async (): Promise<void> => {
  92. try {
  93. uni.showModal({
  94. title: '确认退出',
  95. content: '确定要退出登录吗?',
  96. success: async (res) => {
  97. if (res.confirm) {
  98. // await logoutAndRedirect();
  99. uni.showToast({
  100. title: '已退出登录',
  101. icon: 'success',
  102. });
  103. }
  104. },
  105. });
  106. } catch (error) {
  107. console.error('退出登录失败:', error);
  108. uni.showToast({
  109. title: '退出失败',
  110. icon: 'error',
  111. });
  112. }
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. @import '@/assets/styles/theme.scss';
  117. .user-info-section {
  118. padding: 20rpx;
  119. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  120. .user-card {
  121. display: flex;
  122. align-items: center;
  123. padding: 20rpx;
  124. background: rgba(255, 255, 255, 0.95);
  125. border-radius: 12rpx;
  126. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  127. .user-avatar {
  128. width: 80rpx;
  129. height: 80rpx;
  130. border-radius: 50%;
  131. margin-right: 20rpx;
  132. }
  133. .user-details {
  134. flex: 1;
  135. .user-name {
  136. display: block;
  137. font-size: 32rpx;
  138. font-weight: 600;
  139. color: #333;
  140. margin-bottom: 8rpx;
  141. }
  142. .user-roles {
  143. display: block;
  144. font-size: 24rpx;
  145. color: #666;
  146. }
  147. }
  148. .logout-btn {
  149. padding: 12rpx 24rpx;
  150. background: #f56c6c;
  151. color: #fff;
  152. border: none;
  153. border-radius: 8rpx;
  154. font-size: 24rpx;
  155. }
  156. }
  157. .login-prompt {
  158. display: flex;
  159. align-items: center;
  160. justify-content: space-between;
  161. padding: 20rpx;
  162. background: rgba(255, 255, 255, 0.95);
  163. border-radius: 12rpx;
  164. .prompt-text {
  165. font-size: 28rpx;
  166. color: #666;
  167. }
  168. .login-btn {
  169. padding: 12rpx 24rpx;
  170. background: #667eea;
  171. color: #fff;
  172. border: none;
  173. border-radius: 8rpx;
  174. font-size: 24rpx;
  175. }
  176. }
  177. }
  178. .content {
  179. flex-direction: column;
  180. align-items: center;
  181. justify-content: center;
  182. }
  183. .logo {
  184. height: 200rpx;
  185. width: 200rpx;
  186. margin-top: 200rpx;
  187. margin-left: auto;
  188. margin-right: auto;
  189. margin-bottom: 50rpx;
  190. }
  191. .text-area {
  192. display: flex;
  193. justify-content: center;
  194. }
  195. .title {
  196. font-size: 36rpx;
  197. color: #8f8f94;
  198. }
  199. </style>