index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <view class="project-select-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="header-bg" :style="{ paddingTop: statusBarHeight + 'px' }">
  5. <view class="header-content">
  6. <view class="back-btn" @click="handleBack">
  7. <text class="back-icon">‹</text>
  8. </view>
  9. <text class="header-title">{{ t('projectSelect.title') }}</text>
  10. <view class="placeholder"></view>
  11. </view>
  12. </view>
  13. <!-- 搜索框 -->
  14. <view class="search-bar">
  15. <input
  16. class="search-input"
  17. v-model="searchName"
  18. :placeholder="t('projectSelect.search.placeholder')"
  19. @confirm="handleSearch"
  20. />
  21. <view class="search-btn" @click="handleSearch">
  22. <text class="search-text">{{ t('projectSelect.search.button') }}</text>
  23. </view>
  24. </view>
  25. <!-- 项目列表 -->
  26. <scroll-view
  27. scroll-y
  28. class="project-list"
  29. @scrolltolower="handleLoadMore"
  30. >
  31. <view
  32. v-for="item in projectList"
  33. :key="item.id"
  34. class="project-item"
  35. @click="handleSelectProject(item)"
  36. >
  37. <view class="project-icon-wrapper">
  38. <image
  39. v-if="item.iconUrl"
  40. :src="item.iconUrl"
  41. mode="aspectFit"
  42. class="project-icon"
  43. />
  44. <image
  45. v-else
  46. src="/static/icon/project.svg"
  47. mode="aspectFit"
  48. class="project-icon"
  49. />
  50. </view>
  51. <view class="project-info">
  52. <text class="project-name">{{ item.name }}</text>
  53. <text class="project-detail">{{ t('projectSelect.projectInfo.code') }}: {{ item.code }}</text>
  54. <text class="project-detail">{{ t('projectSelect.projectInfo.type') }}: {{ getProjectTypeLabel(item.type) }}</text>
  55. <text class="project-detail">{{ t('projectSelect.projectInfo.startTime') }}: {{ formatDate(item.startTime) }}</text>
  56. </view>
  57. </view>
  58. <view v-if="projectList.length === 0 && !loading" class="empty-tip">
  59. <text class="empty-text">{{ t('projectSelect.message.empty') }}</text>
  60. </view>
  61. <view v-if="loading" class="loading-tip">
  62. <text class="loading-text">{{ t('projectSelect.message.loading') }}</text>
  63. </view>
  64. </scroll-view>
  65. </view>
  66. </template>
  67. <script setup>
  68. import { ref, onMounted, computed } from 'vue'
  69. import { useI18n } from 'vue-i18n'
  70. import { getProjectList } from '@/apis/scan'
  71. import { getDictDataByType } from '@/apis/dict'
  72. const { locale, t } = useI18n()
  73. // 状态栏高度
  74. const statusBarHeight = ref(0)
  75. // 项目列表
  76. const projectList = ref([])
  77. const searchName = ref('')
  78. const pageNum = ref(1)
  79. const pageSize = ref(10)
  80. const total = ref(0)
  81. const loading = ref(false)
  82. // 字典数据(原始数据)
  83. const projectTypeDictData = ref([])
  84. // 当前语言
  85. const currentLocale = computed(() => {
  86. // 将 zh-CN 转换为 zh_CN 格式
  87. return locale.value.replace('-', '_')
  88. })
  89. onMounted(() => {
  90. // 获取系统信息
  91. const windowInfo = uni.getWindowInfo()
  92. statusBarHeight.value = windowInfo.statusBarHeight || 0
  93. // 加载字典数据
  94. loadDictData()
  95. // 加载项目列表
  96. loadProjectList()
  97. })
  98. // 加载字典数据
  99. const loadDictData = async () => {
  100. try {
  101. const response = await getDictDataByType('project_type')
  102. if (response && response.code === 200 && response.data) {
  103. projectTypeDictData.value = response.data
  104. }
  105. } catch (error) {
  106. console.error('加载字典数据失败:', error)
  107. }
  108. }
  109. // 解析国际化的字典标签
  110. const parseDictLabel = (dictLabel) => {
  111. try {
  112. // 尝试解析 JSON 格式的标签
  113. const labelObj = JSON.parse(dictLabel)
  114. // 返回当前语言对应的标签,如果不存在则返回中文或第一个可用的值
  115. return labelObj[currentLocale.value] || labelObj['zh_CN'] || labelObj['en_US'] || dictLabel
  116. } catch (e) {
  117. // 如果不是 JSON 格式,直接返回原值
  118. return dictLabel
  119. }
  120. }
  121. // 获取项目类型显示文本
  122. const getProjectTypeLabel = (typeValue) => {
  123. const dictItem = projectTypeDictData.value.find(item => item.dictValue === typeValue)
  124. if (dictItem) {
  125. return parseDictLabel(dictItem.dictLabel)
  126. }
  127. return typeValue || '-'
  128. }
  129. // 返回上一页
  130. const handleBack = () => {
  131. uni.navigateBack()
  132. }
  133. // 加载项目列表
  134. const loadProjectList = async () => {
  135. if (loading.value) return
  136. try {
  137. loading.value = true
  138. const params = {
  139. pageNum: pageNum.value,
  140. pageSize: pageSize.value
  141. }
  142. // 搜索关键词使用 content 参数
  143. if (searchName.value && searchName.value.trim()) {
  144. params.content = searchName.value.trim()
  145. }
  146. const response = await getProjectList(params)
  147. if (response.code === 200) {
  148. if (pageNum.value === 1) {
  149. projectList.value = response.rows || []
  150. } else {
  151. projectList.value = [...projectList.value, ...(response.rows || [])]
  152. }
  153. total.value = response.total || 0
  154. }
  155. } catch (error) {
  156. console.error('加载项目列表失败:', error)
  157. uni.showToast({
  158. title: t('projectSelect.message.loadFailed'),
  159. icon: 'none'
  160. })
  161. } finally {
  162. loading.value = false
  163. }
  164. }
  165. // 搜索
  166. const handleSearch = () => {
  167. // 重置分页
  168. pageNum.value = 1
  169. projectList.value = []
  170. loadProjectList()
  171. }
  172. // 加载更多
  173. const handleLoadMore = () => {
  174. if (loading.value) return
  175. if (projectList.value.length >= total.value) return
  176. pageNum.value++
  177. loadProjectList()
  178. }
  179. // 选择项目
  180. const handleSelectProject = async (project) => {
  181. // 从全局数据中获取扫描的fileBase64List
  182. const fileBase64List = getApp().globalData.scannedFileBase64List
  183. if (!fileBase64List || fileBase64List.length === 0) {
  184. uni.showToast({
  185. title: t('projectSelect.message.noScanFile'),
  186. icon: 'none'
  187. })
  188. return
  189. }
  190. // 跳转到上传页面
  191. uni.navigateTo({
  192. url: `/pages/scan/upload/index?projectId=${project.id}&projectName=${encodeURIComponent(project.name)}&projectCode=${encodeURIComponent(project.code)}`
  193. })
  194. }
  195. // 格式化日期(只显示到天)
  196. const formatDate = (dateStr) => {
  197. if (!dateStr) return ''
  198. // 如果日期格式是 "2026-01-04 10:58:37",只取前10位
  199. return dateStr.split(' ')[0]
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .project-select-page {
  204. width: 100%;
  205. height: 100vh;
  206. display: flex;
  207. flex-direction: column;
  208. background-color: #f5f5f5;
  209. // 顶部导航栏
  210. .header-bg {
  211. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  212. position: relative;
  213. z-index: 100;
  214. .header-content {
  215. height: 88rpx;
  216. display: flex;
  217. align-items: center;
  218. justify-content: space-between;
  219. padding: 0 24rpx;
  220. .back-btn {
  221. width: 60rpx;
  222. height: 60rpx;
  223. display: flex;
  224. align-items: center;
  225. justify-content: flex-start;
  226. .back-icon {
  227. font-size: 56rpx;
  228. color: #ffffff;
  229. font-weight: 300;
  230. }
  231. }
  232. .header-title {
  233. flex: 1;
  234. text-align: center;
  235. font-size: 32rpx;
  236. font-weight: 600;
  237. color: #ffffff;
  238. }
  239. .placeholder {
  240. width: 60rpx;
  241. }
  242. }
  243. }
  244. // 搜索框
  245. .search-bar {
  246. padding: 24rpx;
  247. background: #ffffff;
  248. display: flex;
  249. gap: 16rpx;
  250. .search-input {
  251. flex: 1;
  252. height: 64rpx;
  253. padding: 0 24rpx;
  254. background: #f5f5f5;
  255. border-radius: 32rpx;
  256. font-size: 28rpx;
  257. }
  258. .search-btn {
  259. width: 120rpx;
  260. height: 64rpx;
  261. background: #1ec9c9;
  262. border-radius: 32rpx;
  263. display: flex;
  264. align-items: center;
  265. justify-content: center;
  266. &:active {
  267. background: #1ab8b8;
  268. }
  269. .search-text {
  270. font-size: 28rpx;
  271. color: #ffffff;
  272. font-weight: 500;
  273. }
  274. }
  275. }
  276. // 项目列表
  277. .project-list {
  278. flex: 1;
  279. background: #ffffff;
  280. .project-item {
  281. padding: 24rpx;
  282. display: flex;
  283. align-items: center;
  284. border-bottom: 1rpx solid #f5f5f5;
  285. &:active {
  286. background: #f8f8f8;
  287. }
  288. .project-icon-wrapper {
  289. width: 80rpx;
  290. height: 80rpx;
  291. background: #f5f5f5;
  292. border-radius: 12rpx;
  293. display: flex;
  294. align-items: center;
  295. justify-content: center;
  296. margin-right: 24rpx;
  297. .project-icon {
  298. width: 48rpx;
  299. height: 48rpx;
  300. }
  301. }
  302. .project-info {
  303. flex: 1;
  304. display: flex;
  305. flex-direction: column;
  306. gap: 6rpx;
  307. .project-name {
  308. font-size: 32rpx;
  309. font-weight: 600;
  310. color: #333333;
  311. margin-bottom: 4rpx;
  312. }
  313. .project-detail {
  314. font-size: 26rpx;
  315. color: #666666;
  316. line-height: 1.5;
  317. }
  318. }
  319. }
  320. .empty-tip {
  321. padding: 200rpx 0;
  322. text-align: center;
  323. .empty-text {
  324. font-size: 28rpx;
  325. color: #999999;
  326. }
  327. }
  328. .loading-tip {
  329. padding: 32rpx 0;
  330. text-align: center;
  331. .loading-text {
  332. font-size: 28rpx;
  333. color: #999999;
  334. }
  335. }
  336. }
  337. }
  338. </style>