index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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">选择项目</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="搜索项目名称或编号"
  19. @confirm="handleSearch"
  20. />
  21. <view class="search-btn" @click="handleSearch">
  22. <text class="search-text">搜索</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">项目编号: {{ item.code }}</text>
  54. <text class="project-detail">项目类型: {{ getProjectTypeLabel(item.type) }}</text>
  55. <text class="project-detail">开始时间: {{ formatDate(item.startTime) }}</text>
  56. </view>
  57. </view>
  58. <view v-if="projectList.length === 0 && !loading" class="empty-tip">
  59. <text class="empty-text">暂无项目</text>
  60. </view>
  61. <view v-if="loading" class="loading-tip">
  62. <text class="loading-text">加载中...</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 } = 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. // 搜索关键词可以同时匹配项目名称和编号
  143. if (searchName.value && searchName.value.trim()) {
  144. params.name = searchName.value.trim()
  145. params.code = searchName.value.trim()
  146. }
  147. const response = await getProjectList(params)
  148. if (response.code === 200) {
  149. if (pageNum.value === 1) {
  150. projectList.value = response.rows || []
  151. } else {
  152. projectList.value = [...projectList.value, ...(response.rows || [])]
  153. }
  154. total.value = response.total || 0
  155. }
  156. } catch (error) {
  157. console.error('加载项目列表失败:', error)
  158. uni.showToast({
  159. title: '加载失败',
  160. icon: 'none'
  161. })
  162. } finally {
  163. loading.value = false
  164. }
  165. }
  166. // 搜索
  167. const handleSearch = () => {
  168. // 重置分页
  169. pageNum.value = 1
  170. projectList.value = []
  171. loadProjectList()
  172. }
  173. // 加载更多
  174. const handleLoadMore = () => {
  175. if (loading.value) return
  176. if (projectList.value.length >= total.value) return
  177. pageNum.value++
  178. loadProjectList()
  179. }
  180. // 选择项目
  181. const handleSelectProject = async (project) => {
  182. // 从全局数据中获取扫描的fileBase64List
  183. const fileBase64List = getApp().globalData.scannedFileBase64List
  184. if (!fileBase64List || fileBase64List.length === 0) {
  185. uni.showToast({
  186. title: '未找到扫描文件',
  187. icon: 'none'
  188. })
  189. return
  190. }
  191. // 跳转到文件夹选择页面
  192. uni.navigateTo({
  193. url: `/pages/scan/folderSelect/index?projectId=${project.id}&projectName=${encodeURIComponent(project.name)}`
  194. })
  195. }
  196. // 格式化日期(只显示到天)
  197. const formatDate = (dateStr) => {
  198. if (!dateStr) return ''
  199. // 如果日期格式是 "2026-01-04 10:58:37",只取前10位
  200. return dateStr.split(' ')[0]
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .project-select-page {
  205. width: 100%;
  206. height: 100vh;
  207. display: flex;
  208. flex-direction: column;
  209. background-color: #f5f5f5;
  210. // 顶部导航栏
  211. .header-bg {
  212. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  213. position: relative;
  214. z-index: 100;
  215. .header-content {
  216. height: 88rpx;
  217. display: flex;
  218. align-items: center;
  219. justify-content: space-between;
  220. padding: 0 24rpx;
  221. .back-btn {
  222. width: 60rpx;
  223. height: 60rpx;
  224. display: flex;
  225. align-items: center;
  226. justify-content: flex-start;
  227. .back-icon {
  228. font-size: 56rpx;
  229. color: #ffffff;
  230. font-weight: 300;
  231. }
  232. }
  233. .header-title {
  234. flex: 1;
  235. text-align: center;
  236. font-size: 32rpx;
  237. font-weight: 600;
  238. color: #ffffff;
  239. }
  240. .placeholder {
  241. width: 60rpx;
  242. }
  243. }
  244. }
  245. // 搜索框
  246. .search-bar {
  247. padding: 24rpx;
  248. background: #ffffff;
  249. display: flex;
  250. gap: 16rpx;
  251. .search-input {
  252. flex: 1;
  253. height: 64rpx;
  254. padding: 0 24rpx;
  255. background: #f5f5f5;
  256. border-radius: 32rpx;
  257. font-size: 28rpx;
  258. }
  259. .search-btn {
  260. width: 120rpx;
  261. height: 64rpx;
  262. background: #1ec9c9;
  263. border-radius: 32rpx;
  264. display: flex;
  265. align-items: center;
  266. justify-content: center;
  267. &:active {
  268. background: #1ab8b8;
  269. }
  270. .search-text {
  271. font-size: 28rpx;
  272. color: #ffffff;
  273. font-weight: 500;
  274. }
  275. }
  276. }
  277. // 项目列表
  278. .project-list {
  279. flex: 1;
  280. background: #ffffff;
  281. .project-item {
  282. padding: 24rpx;
  283. display: flex;
  284. align-items: center;
  285. border-bottom: 1rpx solid #f5f5f5;
  286. &:active {
  287. background: #f8f8f8;
  288. }
  289. .project-icon-wrapper {
  290. width: 80rpx;
  291. height: 80rpx;
  292. background: #f5f5f5;
  293. border-radius: 12rpx;
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. margin-right: 24rpx;
  298. .project-icon {
  299. width: 48rpx;
  300. height: 48rpx;
  301. }
  302. }
  303. .project-info {
  304. flex: 1;
  305. display: flex;
  306. flex-direction: column;
  307. gap: 6rpx;
  308. .project-name {
  309. font-size: 32rpx;
  310. font-weight: 600;
  311. color: #333333;
  312. margin-bottom: 4rpx;
  313. }
  314. .project-detail {
  315. font-size: 26rpx;
  316. color: #666666;
  317. line-height: 1.5;
  318. }
  319. }
  320. }
  321. .empty-tip {
  322. padding: 200rpx 0;
  323. text-align: center;
  324. .empty-text {
  325. font-size: 28rpx;
  326. color: #999999;
  327. }
  328. }
  329. .loading-tip {
  330. padding: 32rpx 0;
  331. text-align: center;
  332. .loading-text {
  333. font-size: 28rpx;
  334. color: #999999;
  335. }
  336. }
  337. }
  338. }
  339. </style>