Pārlūkot izejas kodu

camera功能优化处理

oyq28 3 dienas atpakaļ
vecāks
revīzija
bab8ca63a1

+ 39 - 9
api/work.uts

@@ -1,5 +1,5 @@
 // #ifdef APP-ANDROID
-import {selectTableData, insertTableData} from '@/utils/sqlite'
+import {selectTableData, insertTableData, updateTableData, selectJoinTableData} from '@/utils/sqlite'
 // #endif
 
 export type Download = {
@@ -38,7 +38,26 @@ export type Record = {
 		num : number
 		step : number
 		status : number
-	}
+ }
+ 
+ export type JoinRecord = {
+	 sxid : number,
+	 senum : number,
+	 photoitem : string,
+	 productno : string,
+	 part : string,
+	 descb : string,
+	 date : string,
+	 partno : string,
+	 num : number,
+	 status : string,
+	 urlspl : string
+	 imgname : string,
+	 urlpdt : string
+	 workorder: string
+	 invname: string
+ }
+  
 
 export function offlineData(data:UTSJSONObject):Promise<UTSJSONObject> {
 	return new Promise((resolve, reject) => {	
@@ -63,10 +82,21 @@ export async function getList(tableName:string, condition?:string|null, value?:s
   // #endif
 }
 
-/*
-export const onload=():Promise<UTSJSONObject>=> {
-  return new Promise((resolve, reject) => {
-	  getInfo().then((res:UTSJSONObject) => {
-	  })
-  })
-}  */
+export async function getJoinList(dbTable:string, joinTable:string, labels:string, joinCondition:string, lname?:string, lvalue?:string, others?:string):Promise<UTSJSONObject> {
+   
+    // #ifdef APP-ANDROID
+    const result = await selectJoinTableData(dbTable, joinTable, labels, joinCondition, lname, lvalue, others);
+    console.log(result);
+	return result;
+	// #endif
+}
+
+
+
+export async function updateData(tableName: string, data: string, lname?: string, lvalue?: string):Promise<UTSJSONObject>{
+	// #ifdef APP-ANDROID
+	const result = await updateTableData(tableName, data, lname, lvalue);
+	console.log(result);
+	return result;
+	// #endif
+}

+ 15 - 4
pages/work/record/Camera.uvue

@@ -67,17 +67,28 @@
 				startRecordStatus: false,
 				remain: 0,
 				intervalId: -1,
-				timeoutStr: '30'
+				timeoutStr: '30',
+				recordId: 0,
+				num: 0
 			}
 		},
-		onLoad() {
-
+		onLoad(options) {
+			let recordId = options?.['id'] ?? ''
+			let num = options?.['num'] ?? ''
+			console.log(recordId)
+			if(recordId!=''){
+				this.recordId = parseInt(recordId)
+			}
+			if(num!=''){
+				this.num = parseInt(num)
+			}
 		},
 
 		methods: {
 			handleScanCode() {
+				let params = "path="+this.imageSrc+"&recordId="+this.recordId+"&num="+this.num
 				uni.navigateTo({
-					url: "/pages/work/record/camera-scan-code?path="+this.imageSrc
+					url: "/pages/work/record/camera-scan-code?"+params
 				})
 			},
 			switchDevicePosition() {

+ 3 - 3
pages/work/record/RecordList.uvue

@@ -54,7 +54,7 @@
 				<text class="value">{{ item.num }}</text>
 			</view>
 
-			<button class="cancel-btn" v-if="item.status == '未执行'" @click="cancel(item.sxid)">
+			<button class="cancel-btn" v-if="item.status == '未执行'" @click="cancel(item.sxid, item.num)">
 				拍照
 			</button>
 
@@ -182,9 +182,9 @@
 		closeTags.value[index] = false
 	}
 
-	const cancel = (id : number) => {
+	const cancel = (id : number, num : number) => {
 		uni.navigateTo({
-			url: `/pages/work/record/Camera?id=${id}`
+			url: `/pages/work/record/Camera?id=${id}&num=${num}`
 		})
 	}
 </script>

+ 67 - 20
pages/work/record/camera-scan-code.uvue

@@ -7,6 +7,7 @@
 	  <swiper-item v-for="item in data"  >
 	    <view class="swiper-item" @tap="previewSingleImage(item.image)">
 	      <image class="my-image" :src="item.image" mode="aspectFill"   />
+		  <view class="img-name">{{ item.name }}</view>
 	    </view>
 	  </swiper-item>
 	</swiper>
@@ -16,6 +17,23 @@
       	浏览相册
       </button>
     </view>
+	
+	<view class="camera-scan-code-table">
+		<view class="camera-scan-code-table-pair">
+		     <view class="camera-scan-code-table-pair-label">
+		          <text></text>
+		        </view>
+		        <view class="camera-scan-code-table-pair-value">
+					<checkbox-group @change="checkboxChange">
+					  <view v-for="(item, index) in data">
+						  <checkbox :value="item.name" :checked="true"></checkbox>
+						   {{ dyImgName+"-"+(index+1)}}
+					  </view>
+				    </checkbox-group>
+		        </view>
+		</view>
+    </view>		
+	
 			
 	  <view class="camera-scan-code-back-wrap">
 		  <button class="btn block bg-blue lg round" @click="saveImage">
@@ -30,39 +48,70 @@
   </view>
 </template>
 
-<script>
+<script lang="uts">
   type CameraScanCodeResult = {
     type : string | null;
     result : string | null;
   }
   type ImageItem={
   	 image:string,
-	 name:string
+	 name:string,
+	 checked: boolean
   }
+  import { getJoinList, JoinRecord, updateData } from '@/api/work';
   export default {
     data() {
       return {
         result: null as CameraScanCodeResult | null,
 		swiperDotIndex: 0 as number,
+		recordId: 0,
+		num:0,
+		dyImgName: '',
 		data: [{
 		    image: '/static/images/banner/banner01.png',
-			name: 'banner01.png'
+			name: 'banner01.png',
+			checked: true,
 		  },
 		] as ImageItem[] 	
       }
     },
-	onLoad(options) {
+	onLoad(options) { 
 		let path = options?.['path'] ?? ''
+		let recordId = options?.['recordId'] ?? ''
+		let num = options?.['num'] ?? ''
 		console.log(path)
 		if(path!=''){
 			this.data = []
-			this.data.push({image:path, name:''})
+			this.data.push({image:path, name:'', checked:true})
+		}
+		if(recordId!=''){
+			this.recordId = parseInt(recordId)			
+			getJoinList('app_media_record as r','app_media_info as i', 'r.*,i.workorder,i.invname', 'r.pid=i.pdid', 'sxid', recordId, null).then((res:UTSJSONObject) => {
+				let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
+				if(dataList!=null && dataList.length>0){
+					dataList.forEach(item =>{
+						if(item!=null){  
+						  let record = JSON.parse<JoinRecord>(item.toJSONString());
+						  if(record!=null){
+						  	this.num = record.num;
+							this.dyImgName = record.workorder+record.invname+record.part+record.photoitem+record.partno;
+						  }	
+						}
+					});
+				}
+			});
+		}
+		if(num!=''){
+			this.num = parseInt(num)
 		}
 	},
     methods: {
       navigateBack() {
         uni.navigateBack()
       },
+	  checkboxChange(){
+		  console.log("选择图片名称")
+	  },
 	  chooseImage() {
 	  	uni.chooseImage({
 			sourceType: ['album'],
@@ -70,7 +119,7 @@
 	  			//this.data = res.tempFilePaths; // 获取选中的图片路径
 				this.data = []
 				for(let i=0; i<res.tempFilePaths.length; i++){
-					this.data.push({image: res.tempFilePaths[i], name:''})
+					this.data.push({image: res.tempFilePaths[i], name:'', checked:true})
 				}
 	  		},
 	  		fail: (err) => {
@@ -79,18 +128,16 @@
 	  	});
 	  },
 	  saveImage() {
-		 uni.chooseImage({
-		     count: 1, // 默认9
-		     sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图
-		     sourceType: ['album'], // 可以指定来源是相册还是相机
-		     success: (chooseImageRes) => {
-		       const tempFilePaths = chooseImageRes.tempFilePaths; // 临时文件路径
-		       const tempFiles = chooseImageRes.tempFiles; // 临时文件信息
-		       
-			   //保存图片信息到数据库
-		       
-		     }
-		   });
+		 //let data = 'imgname='++',urlpdt='; 
+		 let updateImgs = this.data.filter(item=>item.checked == true).map(item=>item.image);
+		 let updateNames = this.data.filter(item=>item.checked == true).map(item=>item.name);
+		 let updatedData = 'imgname='+ updateNames.join(",") +',urlpdt='+ updateImgs.join(",")
+		 updateData('app_media_record',updatedData, 'sxid', this.recordId.toString()).then((res:UTSJSONObject) => {
+		 	let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
+		 	if(dataList!=null && dataList.length>0){
+		 		console.log(dataList[0])
+		 	}
+		 });
 	  },
 	  previewSingleImage(imageUrl:string) {		 
 	    uni.previewImage({
@@ -119,10 +166,10 @@
   }
   .camera-scan-code-table {
     background-color: white;
-    margin-top: 20rpx;
+    margin-top: 20px;
   }
   .camera-scan-code-table-pair {
-    height: 60rpx;
+    height: 250px;
     flex-direction: row;
     justify-content: space-between;
     align-items: center;

+ 65 - 0
utils/sqlite.uts

@@ -74,6 +74,71 @@ export function selectTableData (
     })
   }
  } 
+ 
+ // 普通函数
+ // 查询获取数据库里的数据 sql:'SELECT a.*,b.name FROM dbTable a LEFTJOIN joinTbName j on a.pid = j.id WHERE lname = 'lvalue''
+ // 查询 SELECT * FROM 、 dbTable 是表名、 WHERE 查找条件 lname,lvalue 是查询条件的列名和列值
+ // @param {Object} dbTable:表名
+ // @param {Object} lname:列名
+ // @param {Object} lvalue:列中的属性值
+ export function selectJoinTableData (
+   dbTable: string,
+   joinTable: string,
+   labels: string,
+   joinCondition: string,
+   lname?: string,
+   lvalue?: string,
+   others?: string	  
+ ):Promise<UTSJSONObject>
+ {
+   if (dbTable !== null && joinTable !== null && labels !== null && joinCondition !== null ) {
+     // 第一个是表单名称,后两个参数是列表名,用来检索
+ 	 var sql = `SELECT ${labels} FROM ${dbTable} LEFT JOIN ${joinTable} ON ${joinCondition} `;
+     if(lname !== null && lvalue !== null){
+		 sql = sql+ `WHERE ${lname} = '${lvalue}'`;
+	 }
+	 if(others !== null){
+		 sql = sql + others;
+	 }
+	 
+ 	 const sqlite = createSQLiteContext(dbName);
+ 	
+ 	return new Promise<UTSJSONObject>((resolve, reject) => {
+ 	  const selectSqlOptions ={		
+ 		  sql: sql,
+ 		  success: (e: selectSqlOptionsResult) => {
+ 		    console.log(e)
+ 			
+ 		  },
+ 		  fail: (e: selectSqlOptionsResult) => {
+ 		    console.error(e)
+ 		  }		
+ 	  } as selectSqlOptions
+ 	
+ 	  const info = sqlite.selectSql(selectSqlOptions) as selectSqlOptionsResult
+ 	  
+ 	  console.log(info)	
+ 	  const ret = {
+ 		  errMsg: info?.errMsg ?? '',
+ 		  data: info?.data ?? ['']
+ 	  } as UTSJSONObject
+ 	  resolve(ret)
+ 	});	
+ 		
+   } else {
+     return new Promise<UTSJSONObject>((resolve, reject) => {
+ 		const ret = {
+ 			  errMsg: '错误查询',
+ 			  data : ['表名不存在']
+ 		} as UTSJSONObject
+         resolve(ret);		
+     })
+   }
+  } 
+ 
+ 
+ 
+ 
   // 箭头函数
   // 根据条件向表格里添加数据  有数据更新、无数据插入
   // (建表时需要设置主键) 例如 --- "roomid" varchar(50) PRIMARY KEY