Просмотр исходного кода

声像记录列表添加搜索查询功能

zhangxike 5 дней назад
Родитель
Сommit
8b75eac274
3 измененных файлов с 77 добавлено и 6 удалено
  1. 2 2
      api/work.uts
  2. 68 1
      pages/work/record/InfoList.uvue
  3. 7 3
      utils/sqlite.uts

+ 2 - 2
api/work.uts

@@ -263,10 +263,10 @@ export async function getRecordCalculate(tableName : string, value ?: string | n
 	// #endif
 }
 
-export async function getRecordInfoList(initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
+export async function getRecordInfoList(query: string, initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
 
 	// #ifdef APP-ANDROID
-	const result = await selectRecordInfo();
+	const result = await selectRecordInfo(query);
 	console.log(result);
 	return result;
 	// #endif

+ 68 - 1
pages/work/record/InfoList.uvue

@@ -14,6 +14,9 @@
 			<button class="btn btn-first" @click="download">
 				下载数据
 			</button>
+			<button class="btn btn-second" @click="search">
+				搜索
+			</button>
 		</view>
 		<!-- 列表内容 -->
 		<!-- #ifdef APP -->
@@ -122,7 +125,7 @@
 	const map = ref(new Map<number, string>([[1, '未执行'], [2, '执行中'], [3, '执行完'], [4, '有错误']]))
 
 	// #ifdef APP-ANDROID
-	getRecordInfoList(null).then((res : UTSJSONObject) => {
+	getRecordInfoList('', null).then((res : UTSJSONObject) => {
 		console.log(res)
 		let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
 		if (dataList != null && dataList.length > 0) {
@@ -248,6 +251,70 @@
 			}
 		});
 	}
+	
+	const search = async () => {
+		console.log("开始搜索...")
+		console.log(productNo.value)
+		
+		// 检查productNo是否为空
+		if (productNo.value == null || productNo.value.trim() == '') {
+			uni.showToast({
+				title: '请输入产品号',
+				icon: 'error'
+			});
+			return;
+		}
+		
+		// 显示加载提示
+		uni.showLoading({
+			title: '搜索中...'
+		});
+		
+		try {
+			// 使用getRecordInfoList函数并传入productNo.value作为第一个参数
+			let query = `m.productno = '${productNo.value}'`
+			const res = await getRecordInfoList(query, null);
+			console.log('搜索结果:', res);
+			
+			let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>();
+			let searchResults = [] as Download[];
+			
+			if (dataList != null && dataList.length > 0) {
+				dataList.forEach(item => {
+					if (item != null) {
+						try {
+							let download = JSON.parse<Download>(item.toJSONString());
+							if (download != null) {
+								searchResults.push(download);
+							}
+						} catch (e) {
+							console.error('解析数据失败:', e);
+						}
+					}
+				});
+			}
+			
+			// 更新downloads数组,显示搜索结果
+			downloads.value = searchResults;
+			
+			// 如果没有搜索到结果,显示提示
+			if (searchResults.length === 0) {
+				uni.showToast({
+					title: '未找到相关数据',
+					icon: 'none'
+				});
+			}
+		} catch (error) {
+			console.error('搜索失败:', error);
+			uni.showToast({
+				title: '搜索失败,请重试',
+				icon: 'error'
+			});
+		} finally {
+			// 隐藏加载提示
+			uni.hideLoading();
+		}
+	}
 
 	defineExpose({
 		backPressOptions

+ 7 - 3
utils/sqlite.uts

@@ -427,8 +427,11 @@ export function selectRecordData(
 	}
 }
 
-export function selectRecordInfo() : Promise<UTSJSONObject> {
-
+export function selectRecordInfo(query : string) : Promise<UTSJSONObject> {
+	let querySQL = `where 1=1 `
+	if (query != null && query != '') {
+		querySQL += ` and ${query}`
+	}
 	var sql = `SELECT
 					m.*,
 					COUNT(r_stats.part) AS totalRecord,
@@ -450,6 +453,7 @@ export function selectRecordInfo() : Promise<UTSJSONObject> {
 					GROUP BY
 						r.pid, r.part
 				) AS r_stats ON m.pdid = r_stats.pid
+				${querySQL}
 				GROUP BY
 					m.pdid
 				ORDER BY
@@ -457,7 +461,7 @@ export function selectRecordInfo() : Promise<UTSJSONObject> {
 
 
 	const sqlite = createSQLiteContext(dbName);
-
+	
 	return new Promise<UTSJSONObject>((resolve, reject) => {
 		const selectSqlOptions = {
 			sql: sql,