小程序接入保安证号接口
This commit is contained in:
parent
c339455817
commit
90202e7e95
|
@ -30,7 +30,6 @@ class CustomRequest {
|
||||||
BASE_API: string = process.env.TARO_APP_BASE_API;
|
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>> {
|
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) => {
|
return new Promise<JsonResult<T>>((resolve, reject) => {
|
||||||
if (options.loading) {
|
if (options.loading) {
|
||||||
Taro.showLoading({
|
Taro.showLoading({
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
<view class="form">
|
<view class="form">
|
||||||
<nut-form ref="formRef" :model-value="formData" :rules="rules">
|
<nut-form ref="formRef" :model-value="formData" :rules="rules">
|
||||||
<nut-form-item label="头像" prop="avatar">
|
<nut-form-item label="头像" prop="avatar">
|
||||||
<view @click="chooseImage">
|
<view @click="chooseImage" size>
|
||||||
<image v-if="!Url" src="@/assets/logo/avatar1.png" style="width: 50px; height: 50px"></image>
|
<image v-if="!formData.photo" src="@/assets/logo/avatar1.png" style="width: 50px; height: 50px"></image>
|
||||||
<image v-else :src="Url" style="width: 150px; height: 150px"></image>
|
<image v-else :src="minioBaseUrl +formData.photo" style="width: 160px; height: 128px"></image>
|
||||||
</view>
|
</view>
|
||||||
</nut-form-item>
|
</nut-form-item>
|
||||||
<nut-form-item label="身份证" prop="idCard">
|
<nut-form-item label="身份证" prop="idCard">
|
||||||
|
@ -112,6 +112,7 @@ const rules: FormRules = {
|
||||||
}
|
}
|
||||||
|
|
||||||
useLoad((options) => {
|
useLoad((options) => {
|
||||||
|
console.log(options)
|
||||||
type.value = options.type
|
type.value = options.type
|
||||||
if (type.value === 'QcCodeInput') {
|
if (type.value === 'QcCodeInput') {
|
||||||
formData.value = {
|
formData.value = {
|
||||||
|
@ -123,14 +124,14 @@ useLoad((options) => {
|
||||||
telephone: null,
|
telephone: null,
|
||||||
dateOfBirth: null,
|
dateOfBirth: null,
|
||||||
noSecurityNumberDesc: options.noSecurityNumberDesc,
|
noSecurityNumberDesc: options.noSecurityNumberDesc,
|
||||||
photo: options.photo,
|
photo: '',
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const form = JSON.parse(options.securityUser)
|
const form = JSON.parse(options.securityUser)
|
||||||
console.log(form)
|
|
||||||
formData.value = Object.assign({}, form, {
|
formData.value = Object.assign({}, form, {
|
||||||
idCard: form.idCard.originalValue,
|
idCard: form.idCard.originalValue,
|
||||||
telephone: form.telephone.originalValue,
|
telephone: form.telephone.originalValue,
|
||||||
|
photo: form.photo
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -188,21 +189,19 @@ const cancel = () => {
|
||||||
const chooseImage = () => {
|
const chooseImage = () => {
|
||||||
Taro.chooseMedia({
|
Taro.chooseMedia({
|
||||||
count: 1, // 选择一个文件
|
count: 1, // 选择一个文件
|
||||||
// type: 'image', // 可以选择所有文件类型
|
|
||||||
mediaType: ['image', 'video'],
|
mediaType: ['image', 'video'],
|
||||||
sourceType: ['album', 'camera'],
|
sourceType: ['album', 'camera'],
|
||||||
maxDuration: 30,
|
maxDuration: 30,
|
||||||
camera: 'back',
|
camera: 'front',
|
||||||
success: async (res) => {
|
success: async (res) => {
|
||||||
console.log('🚀 ~ success: ~ res:', res)
|
Url.value = res.tempFiles[0].tempFilePath
|
||||||
|
const objectName = generateSimpleObjectName(Url.value, '/securityUser')
|
||||||
const tempFilePath = res.tempFiles[0].tempFilePath
|
|
||||||
const objectName = generateSimpleObjectName(tempFilePath, '/securityUser')
|
|
||||||
const uploadUrl = await getResignedObjectUrl(process.env.TARO_APP_MINIO_BUCKET, objectName)
|
const uploadUrl = await getResignedObjectUrl(process.env.TARO_APP_MINIO_BUCKET, objectName)
|
||||||
|
|
||||||
|
modelValue.value = '/' + process.env.TARO_APP_MINIO_BUCKET + objectName
|
||||||
// 使用 wx.getFileSystemManager().readFileSync 读取文件的二进制内容
|
// 使用 wx.getFileSystemManager().readFileSync 读取文件的二进制内容
|
||||||
const fs = Taro.getFileSystemManager()
|
const fs = Taro.getFileSystemManager()
|
||||||
const fileData = fs.readFileSync(tempFilePath) // 返回的是文件的二进制内容
|
const fileData = fs.readFileSync(Url.value) // 返回的是文件的二进制内容
|
||||||
|
|
||||||
// 发送 PUT 请求上传二进制文件
|
// 发送 PUT 请求上传二进制文件
|
||||||
Taro.request({
|
Taro.request({
|
||||||
url: uploadUrl, // 后端上传接口
|
url: uploadUrl, // 后端上传接口
|
||||||
|
@ -212,6 +211,7 @@ const chooseImage = () => {
|
||||||
},
|
},
|
||||||
data: fileData, // 传递二进制数据
|
data: fileData, // 传递二进制数据
|
||||||
success(res) {
|
success(res) {
|
||||||
|
formData.value.photo = modelValue.value
|
||||||
console.log('上传成功', res)
|
console.log('上传成功', res)
|
||||||
},
|
},
|
||||||
fail(err) {
|
fail(err) {
|
||||||
|
@ -223,74 +223,9 @@ const chooseImage = () => {
|
||||||
console.error('选择文件失败', err)
|
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 = () => {
|
const submit = () => {
|
||||||
console.log(formData.value.photo)
|
formData.value.photo = modelValue.value
|
||||||
formRef.value?.validate().then(async ({ valid }) => {
|
formRef.value?.validate().then(async ({ valid }) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
let url: string
|
let url: string
|
||||||
|
|
Loading…
Reference in New Issue