小程序接入保安证号接口

This commit is contained in:
wangyilin 2024-12-02 13:48:51 +08:00
parent c339455817
commit 90202e7e95
2 changed files with 14 additions and 80 deletions

View File

@ -30,7 +30,6 @@ class CustomRequest {
BASE_API: string = process.env.TARO_APP_BASE_API;
private request<T>(url: string, method: keyof Taro.request.Method, options: ApiOptions, params?: object,): Promise<JsonResult<T>> {
console.log(this.BASE_API,'0000000')
return new Promise<JsonResult<T>>((resolve, reject) => {
if (options.loading) {
Taro.showLoading({

View File

@ -2,9 +2,9 @@
<view class="form">
<nut-form ref="formRef" :model-value="formData" :rules="rules">
<nut-form-item label="头像" prop="avatar">
<view @click="chooseImage">
<image v-if="!Url" src="@/assets/logo/avatar1.png" style="width: 50px; height: 50px"></image>
<image v-else :src="Url" style="width: 150px; height: 150px"></image>
<view @click="chooseImage" size>
<image v-if="!formData.photo" src="@/assets/logo/avatar1.png" style="width: 50px; height: 50px"></image>
<image v-else :src="minioBaseUrl +formData.photo" style="width: 160px; height: 128px"></image>
</view>
</nut-form-item>
<nut-form-item label="身份证" prop="idCard">
@ -112,6 +112,7 @@ const rules: FormRules = {
}
useLoad((options) => {
console.log(options)
type.value = options.type
if (type.value === 'QcCodeInput') {
formData.value = {
@ -123,14 +124,14 @@ useLoad((options) => {
telephone: null,
dateOfBirth: null,
noSecurityNumberDesc: options.noSecurityNumberDesc,
photo: options.photo,
photo: '',
}
} else {
const form = JSON.parse(options.securityUser)
console.log(form)
formData.value = Object.assign({}, form, {
idCard: form.idCard.originalValue,
telephone: form.telephone.originalValue,
photo: form.photo
})
}
})
@ -188,21 +189,19 @@ const cancel = () => {
const chooseImage = () => {
Taro.chooseMedia({
count: 1, //
// type: 'image', //
mediaType: ['image', 'video'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
camera: 'front',
success: async (res) => {
console.log('🚀 ~ success: ~ res:', res)
const tempFilePath = res.tempFiles[0].tempFilePath
const objectName = generateSimpleObjectName(tempFilePath, '/securityUser')
Url.value = res.tempFiles[0].tempFilePath
const objectName = generateSimpleObjectName(Url.value, '/securityUser')
const uploadUrl = await getResignedObjectUrl(process.env.TARO_APP_MINIO_BUCKET, objectName)
modelValue.value = '/' + process.env.TARO_APP_MINIO_BUCKET + objectName
// 使 wx.getFileSystemManager().readFileSync
const fs = Taro.getFileSystemManager()
const fileData = fs.readFileSync(tempFilePath) //
const fileData = fs.readFileSync(Url.value) //
// PUT
Taro.request({
url: uploadUrl, //
@ -212,6 +211,7 @@ const chooseImage = () => {
},
data: fileData, //
success(res) {
formData.value.photo = modelValue.value
console.log('上传成功', res)
},
fail(err) {
@ -223,74 +223,9 @@ const chooseImage = () => {
console.error('选择文件失败', err)
},
})
// Taro.chooseImage({
// count: 1,
// sizeType: ['original', 'compressed'],
// sourceType: ['album', 'camera'],
// success: async (resp) => {
// Url.value = resp.tempFilePaths[0]
// console.log(resp.tempFilePaths[0])
// const objectName = generateSimpleObjectName(resp.tempFiles[0].path, '/securityUser')
// const uploadUrl = await getResignedObjectUrl(process.env.TARO_APP_MINIO_BUCKET, objectName)
// modelValue.value = '/' + process.env.TARO_APP_MINIO_BUCKET + objectName;
// console.log(modelValue)
// // Taro.request({
// // url: uploadUrl,
// // data: resp.tempFiles,
// // method: 'PUT',
// // header: {
// // 'content-type': 'application/json'
// // },
// // success: (resp) => {
// // console.log(resp)
// // }
// // })
// Taro.getFileSystemManager().readFile({
// filePath: resp.tempFiles[0].path, //
// encoding: 'base64', // base64
// success (res) {
// console.log(res.data)
// // Blob
// const blob = b64toBlob(res.data, 'image/jpeg'); // MIME
// // File
// const file = new File([blob], 'filename.jpg', {type: 'image/jpeg'});
// console.log(file)
// Taro.request({
// url:uploadUrl,
// data: file,
// method:'PUT',
// success:(res)=>{
// console.log(res)
// }
// })
// // 使 file
// },
// fail (err) {
// console.error(':', err);
// }
// });
// }
// })
}
const b64toBlob = (b64Data, contentType = '', sliceSize = 512) => {
const byteCharacters = atob(b64Data)
const byteArrays: any = []
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize)
const byteNumbers = new Array(slice.length)
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i)
}
const byteArray = new Uint8Array(byteNumbers)
byteArrays.push(byteArray)
}
return new Blob(byteArrays, { type: contentType })
}
const submit = () => {
console.log(formData.value.photo)
formData.value.photo = modelValue.value
formRef.value?.validate().then(async ({ valid }) => {
if (valid) {
let url: string