小程序接入保安证号接口
This commit is contained in:
parent
c339455817
commit
90202e7e95
|
@ -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({
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue