Commit 2d2a2b48 by cen

fix: 修复显示问题

1 parent 166d259f
No preview for this file type
......@@ -220,7 +220,7 @@ export default {
otherImagesData: {},
currentStep: 1, // 当前步骤,默认为1
formFields: [
{ key: 'sellerUserId', label: '销售顾问', required: true, fullWidth: false, targetNameKey: 'sellerName', sourceNameKey: 'staffName', sourceKey: 'uuid', targetKey: 'sellerUserId', targetObj: 'evalOrderBasicReqDTO', type: 'select', showText: 'shopMerchantName' },
{ key: 'sellerUserId', label: '销售顾问', required: true, fullWidth: false, targetNameKey: 'sellerName', sourceNameKey: 'staffName', sourceKey: 'uuid', targetKey: 'sellerUserId', targetObj: 'evalOrderBasicReqDTO', type: 'select' },
{ key: 'brandModel', label: '品牌车型', required: true, fullWidth: false, targetNameKey: 'carBrand', sourceNameKey: 'staffName', sourceKey: 'uuid', targetKey: 'carBrandId', targetObj: 'carBaseReqDTO', type: 'select', isCar: true },
{ key: 'vin', label: '车架号', required: true, maxlength: 17, fullWidth: false, targetNameKey: 'sellerName', sourceNameKey: 'staffName', sourceKey: 'uuid', targetKey: 'vin', targetObj: 'carBaseReqDTO', type: 'input', showText: 'shopMerchantName', isScan: true, pattern: '^[A-Z0-9]{17}$' },
{ key: 'licensePlate', label: '车牌号', required: true, maxlength: 10, fullWidth: false, targetNameKey: 'sellerName', sourceNameKey: 'staffName', sourceKey: 'uuid', targetKey: 'licensePlate', targetObj: 'carBaseReqDTO', type: 'input', showText: 'shopMerchantName' },
......@@ -454,7 +454,7 @@ export default {
targetKey: 'conditionDescription',
targetObj: 'carBaseReqDTO',
type: 'textarea',
maxlength: 1000
maxlength: 200
}
],
licenseFormFields: [
......@@ -1011,6 +1011,7 @@ export default {
if (res.data.code == 0) {
if (res.data.data.status == 1) {
this.formData.carBaseReqDTO.vin = res.data.data.vin
uni.showToast({ title: '车架号识别完成并已自动填写到表单中', icon: 'none' })
uni.hideLoading()
} else {
uni.showToast({ title: res.data.data.errorMessage, icon: 'none' })
......@@ -1038,6 +1039,7 @@ export default {
console.log('res:', res)
uni.hideLoading()
if (res.data.code == 0) {
uni.showToast({ title: '行驶证信息识别完成,已自动填写到表单中', icon: 'none' })
if (res.data.data.status == 1) {
this.formData.carBaseReqDTO.engineNumber = res.data.data.engineNumber
if (this.title == '新增评估单') {
......
<template>
<div class="button-module flex">
<view class="common-btn" @click.stop="handleClick('details')">详情</view>
<view v-if="!subStatus && status != 100" class="common-btn ml-24" @click.stop="handleClick('edit')">编辑</view>
<view v-if="status == 20 && !subStatus" class="common-btn ml-24" @click.stop="handleClick('requote','app_evaluate_requote')">重新报价</view>
<view v-if="status == 20 && !subStatus" class="common-btn blue-btn ml-24" @click.stop="handleClick('sign','app_evaluate_sign')">客户签约</view>
<view v-if="!subStatus && status != 100 && status != '-1'" class="common-btn ml-24" @click.stop="handleClick('edit')">编辑</view>
<view v-if="status == 20 && !subStatus" class="common-btn ml-24" @click.stop="handleClick('requote', 'app_evaluate_requote')">重新报价</view>
<view v-if="status == 20 && !subStatus" class="common-btn blue-btn ml-24" @click.stop="handleClick('sign', 'app_evaluate_sign')">客户签约</view>
<view v-if="status == 20 && subStatus == 1" class="common-btn gray-btn ml-24" @click.stop="handleClick('signing')">签约中</view>
<view v-if="status == 30 && !subStatus" class="common-btn ml-24" @click.stop="handleClick('cancelSign','app_evaluate_cancel_sign')">取消签约</view>
<view v-if="status == 30 && !subStatus && paymentType == 1" class="common-btn blue-btn ml-24" @click.stop="handleClick('payDeposit','app_evaluate_pay_deposit')">支付定金</view>
<view v-if="status == 30 && !subStatus && paymentType == 2" class="common-btn blue-btn ml-24" @click.stop="handleClick('payFull','app_evaluate_pay_full')">支付全款</view>
<view v-if="status == 30 && !subStatus" class="common-btn ml-24" @click.stop="handleClick('cancelSign', 'app_evaluate_cancel_sign')">取消签约</view>
<view v-if="status == 30 && !subStatus && paymentType == 1" class="common-btn blue-btn ml-24" @click.stop="handleClick('payDeposit', 'app_evaluate_pay_deposit')">支付定金</view>
<view v-if="status == 30 && !subStatus && paymentType == 2" class="common-btn blue-btn ml-24" @click.stop="handleClick('payFull', 'app_evaluate_pay_full')">支付全款</view>
<view v-if="subStatus == 2 || subStatus == 3" class="common-btn gray-btn ml-24" @click.stop="handleClick('paying')">支付中</view>
<view v-if="status == 40 && !subStatus && paymentType == 1" class="common-btn blue-btn ml-24" @click.stop="handleClick('payFull','app_evaluate_pay_final')">支付尾款</view>
<view v-if="status == 50 && !subStatus" class="common-btn blue-btn ml-24" @click.stop="handleClick('confirmDelivery','app_evaluate_confirm_delivery')">确认交车</view>
<view v-if="status == '-1'" class="common-btn blue-btn ml-24" @click.stop="handleClick('reSubmit','app_evaluate_re_submit')">重新提交</view>
<view v-if="status == 40 && !subStatus && paymentType == 1" class="common-btn blue-btn ml-24" @click.stop="handleClick('payFull', 'app_evaluate_pay_final')">支付尾款</view>
<view v-if="status == 50 && !subStatus" class="common-btn blue-btn ml-24" @click.stop="handleClick('confirmDelivery', 'app_evaluate_confirm_delivery')">确认交车</view>
<view v-if="status == '-1'" class="common-btn blue-btn ml-24" @click.stop="handleClick('reSubmit', 'app_evaluate_re_submit')">重新提交</view>
</div>
</template>
......@@ -38,13 +38,14 @@ export default {
}
},
methods: {
handleClick(buttonType ,eventCode) {
handleClick(buttonType, eventCode) {
this.$emit('button-click', {
type: buttonType
})
if(eventCode) uni.$track.add({
eventCode
}) //点击埋点
if (eventCode)
uni.$track.add({
eventCode
}) //点击埋点
}
}
}
......
......@@ -24,7 +24,7 @@
{{ field.targetObj ? formData[field.targetObj][field.targetNameKey] : formData[field.targetNameKey] }}
</view>
<view v-else-if="field.isCar">
{{ formData.carBaseReqDTO.carSeriesName + ' ' + formData.carBaseReqDTO.carTypeName }}
{{ formData.carBaseReqDTO.carChildsBrandName + ' ' + formData.carBaseReqDTO.carTypeName }}
</view>
<view v-else-if="field.isCity">
{{ formData.carBaseReqDTO.registrationProvinceName + ' ' + formData.carBaseReqDTO.registrationCityName }}
......@@ -272,6 +272,9 @@ export default {
text-align: right;
outline: none;
}
.formInput:disabled {
color: #999999;
}
.cellLabel {
color: #333333;
font-size: toRpx(28);
......
......@@ -12,7 +12,7 @@
<image :src="carInfo.coverImage" alt="" />
<view class="ml-32 flex-1">
<view class="flex align-center car-type-name mb-16">
{{ carInfo.carSeriesName + ' ' + carInfo.carTypeName }}
{{ carInfo.carChildsBrandName + ' ' + carInfo.carTypeName }}
<view class="common-label ml-20">{{ carInfo.previousOwnerName }} {{ carInfo.previousOwnerPhone }}</view>
</view>
<view class="flex mb-20">
......
......@@ -59,7 +59,7 @@ export default {
popKey: 'licensePlate'
},
{
placeholder: '评估单号',
placeholder: '工单编号',
key: 'carModel',
type: 'input',
popKey: 'evalOrderNo'
......
......@@ -35,7 +35,8 @@
</view>
</template>
<script>
import { uploadFile } from '@/utils/ossUploadFile/uploadFile.js'
// import { uploadFile } from '@/utils/ossUploadFile/uploadFile.js'
import { uploadFile } from '@/utils/ossUpload.js'
export default {
name: 'UploadMedia',
......@@ -117,6 +118,13 @@ export default {
sourceType: ['camera'],
success: async res => {
try {
const MAX_IMAGE_SIZE = 10 * 1024 * 1024 // 10MB
for (const file of res.tempFiles) {
if (file.size > MAX_IMAGE_SIZE) {
uni.showToast({ title: '图片上传最大10MB', icon: 'none' })
return
}
}
uni.showLoading({ title: '上传中...' })
// 上传所有选择的图片
for (const tempFilePath of res.tempFilePaths) {
......@@ -129,7 +137,7 @@ export default {
}
} catch (error) {
console.log('上传图片失败', error)
uni.showToast({ title: '上传图片失败', icon: 'none' })
uni.showToast({ title: '图片上传失败,请重试', icon: 'none' })
}
},
fail: err => {
......@@ -149,12 +157,19 @@ export default {
sizeType: ['compressed'],
sourceType: ['album'],
success: async res => {
console.log(res, '选择图片')
try {
const MAX_IMAGE_SIZE = 10 * 1024 * 1024 // 10MB
for (const file of res.tempFiles) {
if (file.size > MAX_IMAGE_SIZE) {
uni.showToast({ title: '图片上传最大10MB', icon: 'none' })
return
}
}
uni.showLoading({ title: '上传中...' })
// 上传所有选择的图片
for (const tempFilePath of res.tempFilePaths) {
console.log(res, '上传所有选择的图片')
const url = await uploadFile(tempFilePath)
for (let i = 0; i < res.tempFilePaths.length; i++) {
const url = await uploadFile(res.tempFiles[i], res.tempFilePaths[i])
console.log('上传图片成功', url)
uni.hideLoading()
// const fileExtension = res.tempFiles[0]?.name ? res.tempFiles[0]?.name.split('.').pop().toLowerCase() : res.tempFiles[0]?.path.split('.').pop().toLowerCase()
......@@ -162,7 +177,7 @@ export default {
}
} catch (error) {
console.log('上传图片失败', error)
uni.showToast({ title: '上传图片失败', icon: 'none' })
uni.showToast({ title: '图片上传失败,请重试', icon: 'none' })
}
},
fail: err => {
......@@ -184,8 +199,18 @@ export default {
success: async res => {
console.log('拍摄视频成功', res)
try {
const MAX_VIDEO_SIZE = 100 * 1024 * 1024 // 100MB
if (res.size > MAX_VIDEO_SIZE) {
uni.showToast({ title: '视频上传最大100MB', icon: 'none' })
return
}
uni.showLoading({ title: '上传中...' })
const url = await uploadFile(res.tempFilePath)
// #ifdef H5
const url = await uploadFile(res.tempFile, res.tempFilePath)
// #endif
// #ifdef APP-PLUS
const url = await uploadFile(null, res.tempFilePath)
// #endif
console.log('上传视频成功', url)
// const fileExtension = res.name ? res.name.split('.').pop().toLowerCase() : res.tempFilePath.split('.').pop().toLowerCase()
this.addMedia(field, {
......@@ -200,7 +225,7 @@ export default {
} catch (error) {
console.log('上传视频失败', error)
uni.hideLoading()
uni.showToast({ title: '上传视频失败', icon: 'none' })
uni.showToast({ title: '视频上传失败,请重试', icon: 'none' })
}
},
fail: err => {
......@@ -221,8 +246,19 @@ export default {
success: async res => {
console.log('选择视频成功', res)
try {
const MAX_VIDEO_SIZE = 100 * 1024 * 1024 // 100MB
if (res.size > MAX_VIDEO_SIZE) {
uni.showToast({ title: '视频上传最大100MB', icon: 'none' })
return
}
uni.showLoading({ title: '上传中...' })
const url = await uploadFile(res.tempFilePath)
// #ifdef H5
const url = await uploadFile(res.tempFile, res.tempFilePath)
// #endif
// #ifdef APP-PLUS
const url = await uploadFile(null, res.tempFilePath)
// #endif
console.log('上传视频成功', url)
// const fileExtension = res.name ? res.name.split('.').pop().toLowerCase() : res.tempFilePath.split('.').pop().toLowerCase()
this.addMedia(field, {
......@@ -237,7 +273,7 @@ export default {
} catch (error) {
console.log('上传视频失败', error)
uni.hideLoading()
uni.showToast({ title: '上传视频失败', icon: 'none' })
uni.showToast({ title: '视频上传失败,请重试', icon: 'none' })
}
},
fail: err => {
......
......@@ -37,13 +37,16 @@
<view v-if="activeTabKey == 'carInfo'" class="gridBox">
<view v-for="(item, index) in carInfoItems" :key="index" :class="['flex align-center', { 'full-width': item.fullWidth }]">
<view class="title-label-see mr-16">{{ item.label }}</view>
<view class="flex-1">{{ formatValue(item, detailsInfo) || '-' }}</view>
<view class="flex-1">
{{ formatValue(item, detailsInfo) }}
<text>{{ item.cell }}</text>
</view>
</view>
</view>
<view v-else-if="activeTabKey == 'carLicense'" class="gridBox mb-32">
<view v-for="(item, index) in carLicenseItems" :key="index" :class="['flex align-center', { 'full-width': item.fullWidth }]">
<view class="title-label-see mr-16">{{ item.label }}</view>
<view class="flex-1">{{ formatValue(item, detailsInfo) || '-' }}</view>
<view class="flex-1">{{ formatValue(item, detailsInfo) }}</view>
</view>
</view>
<view v-else-if="activeTabKey == 'images'">
......@@ -155,7 +158,7 @@
</view>
</view>
</view>
<view v-else>{{ formatValue(item, detailsInfo) || '-' }}</view>
<view v-else>{{ formatValue(item, detailsInfo) }}</view>
</view>
</view>
</view>
......@@ -176,7 +179,7 @@
</view>
</view>
</view>
<view v-else>{{ formatValue(item, detailsInfo) || '-' }}</view>
<view v-else>{{ formatValue(item, detailsInfo) }}</view>
</view>
</template>
</view>
......@@ -198,7 +201,7 @@
</view>
</view>
</view>
<view v-else>{{ formatValue(item, detailsInfo) || '-' }}</view>
<view v-else>{{ formatValue(item, detailsInfo) }}</view>
</view>
</template>
</view>
......@@ -431,14 +434,14 @@ export default {
],
carInfoItems: [
{ label: '销售顾问', key: 'basic.sellerName' },
{ label: '品牌车型', key: 'carInfo.carSeriesName', formatter: (val, data) => `${val} ${data.carInfo.carTypeName}` },
{ label: '品牌车型', key: 'carInfo.carChildsBrandName', formatter: (val, data) => `${val} ${data.carInfo.carTypeName}` },
{ label: '车架号', key: 'carInfo.vin' },
{ label: '车牌号', key: 'carInfo.licensePlate' },
{ label: '发动机号', key: 'carInfo.engineNumber' },
{ label: '上牌时间', key: 'carInfo.registrationDate' },
{ label: '上牌城市', key: 'carInfo.registrationCityName' },
{ label: '车辆所在地', key: 'carInfo.carProvinceName', formatter: (val, data) => `${val}-${data.carInfo.carCityName}` },
{ label: '表显里程', key: 'carInfo.mileage' },
{ label: '表显里程', key: 'carInfo.mileage', cell: '公里' },
{ label: '使用性质', key: 'carInfo.usageType', map: 'usageTypeMap' },
{ label: '所有人性质', key: 'carInfo.ownerType', map: 'ownerTypeMap' },
{ label: '天窗', key: 'carInfo.sunroof', map: 'sunroofMap' },
......@@ -447,7 +450,7 @@ export default {
{ label: '外观颜色', key: 'carInfo.exteriorColor' },
{ label: '内饰颜色', key: 'carInfo.interiorColor' },
{ label: '生产日期', key: 'carInfo.productionDate' },
{ label: '指导价', key: 'carInfo.guidePrice' },
{ label: '指导价', key: 'carInfo.guidePrice', cell: '元' },
{ label: '是否购买新车', key: 'carInfo.buyNewCar', map: 'buyNewCarMap' },
{ label: '是否事故车', key: 'carInfo.hasAccident', map: 'hasAccidentMap' },
{ label: '综合评价', key: 'carInfo.overallRating', map: 'overallRatingMap', fullWidth: true },
......@@ -664,33 +667,26 @@ export default {
formatValue(item, data) {
const rawValue = this.getFieldValue(data, item.key)
// 如果有自定义格式化器,使用它
if (item.formatter && typeof item.formatter === 'function') {
return item.formatter(rawValue, data)
}
// 如果有映射表,使用映射表
if (item.map && this[item.map]) {
return this[item.map][rawValue] || rawValue
}
console.log('rawValue:', rawValue, item.key)
// 返回原始值(如果为空则返回空字符串)
return rawValue || ''
return rawValue == 0 ? 0 : rawValue || ''
},
// 根据fileSubtype获取图片
getImageBySubtype(subtype) {
if (!this.detailsInfo.images) return []
// 对于fileSubtype=41,返回所有匹配的图片数组
if (subtype === 41) {
return this.detailsInfo.images.filter(img => img.fileSubtype === subtype)
}
// 对于其他subtype,保持原有行为返回第一个匹配的图片
const obj = this.detailsInfo.images.find(img => img.fileSubtype === subtype) || null
return obj
},
// 获取图片标签名称
getImageLabel(fileSubtype) {
// 这里使用已有的fileSuibtype映射
return this.fileSuibtype[fileSubtype]?.name || `未知类型(${fileSubtype})`
},
previewMedia(media, type) {
......
......@@ -24,7 +24,7 @@
<view class="addBtn" @click.stop="addEvaluationForm({ type: 'add' })">
<view class="sprite-icon icon-addEvaluationFrom"></view>
</view>
<GeneralPopup ref="requotePopup" popupClass="requotePopup" title="重新报价" confirmText="重新报价" type="center" :showClose="true" :isShowCancel="false" :autoClose="false" @confirm="confirmRequote">
<GeneralPopup ref="requotePopup" popupClass="requotePopup" title="重新报价" confirmText="申请重新报价" type="center" :showClose="true" :isShowCancel="false" :autoClose="false" @confirm="confirmRequote">
<template #content>
<view class="requote-content">
<view class="requote-label mb-24">
......@@ -32,12 +32,12 @@
<text class="requiredLabel">*</text>
</view>
<view class="flex align-center intention-input-cell mb-48">
<input class="flex-1" type="number" maxlength="6" placeholder="请输入" v-model="requoteObj.customerTargetPrice" />
<input class="flex-1" type="number" maxlength="6" placeholder="请输入" :value="requoteObj.customerTargetPrice" @input="handlePriceInput" />
<text>元</text>
</view>
<view class="requote-label mb-24">
客户意向报价
客户报价反馈
<text class="requiredLabel">*</text>
</view>
<textarea class="feedback-textarea" placeholder-style="color:#999999" placeholder="请输入 (200字以内)" maxlength="200" v-model="requoteObj.customerTargetPriceFeedback" />
......@@ -156,6 +156,7 @@ import EvaluationCard from './components/evaluationCard.vue'
import ZPMixin from '@/uni_modules/z-paging/components/z-paging/js/z-paging-mixin'
import GeneralPopup from './components/GeneralPopup.vue'
import OrderPopup from '@/components/OrderPopup/index.vue'
import { set } from 'lodash'
export default {
name: 'EvaluationFormList',
mixins: [ZPMixin],
......@@ -266,8 +267,10 @@ export default {
if (pageNo == 1) {
this.getStatByStatus()
}
const userInfo = uni.$storage.get('userInfo'),
{ shopMerchantId } = userInfo
const res = await uni.$api.evaluationApi.evalOrderList({
t: { ...this.searchValue, status: this.typeList[this.tabIndex].key },
t: { ...this.searchValue, status: this.typeList[this.tabIndex].key, sellerMerchantId: shopMerchantId },
currentPage: pageNo,
pageSize: 10
})
......@@ -312,6 +315,12 @@ export default {
}
})
},
handlePriceInput(e) {
console.log(e)
const value = e.target ? e.target.value.replace(/[^0-9]/g, '') : e.detail.value.replace(/[^0-9]/g, '')
console.log('value:', value)
this.$set(this.requoteObj, 'customerTargetPrice', value)
},
addEvaluationForm(e) {
console.log('addEvaluationForm', e.type)
uni.navigateTo({
......@@ -352,12 +361,14 @@ export default {
if (res.data.code == 0) {
uni.hideLoading()
uni.showToast({
title: res.data.data || '请求成功',
title: '订单已重置回「评估中」',
icon: 'none',
duration: 3000
})
this.currentPage = 1
this.search()
setTimeout(() => {
this.currentPage = 1
this.search()
}, 500)
} else {
uni.hideLoading()
uni.showToast({
......@@ -394,8 +405,10 @@ export default {
title: '定金已申请,请等待付款审批',
icon: 'none'
})
that.currentPage = 1
that.search()
setTimeout(() => {
that.currentPage = 1
that.search()
}, 500)
}
} else {
uni.showLoading()
......@@ -416,7 +429,7 @@ export default {
if (res.data.code == 0) {
uni.hideLoading()
uni.showToast({
title: '代保管协议已发送',
title: '电子签约已发送,请注意查收短信',
icon: 'none'
})
that.currentPage = 1
......@@ -488,15 +501,18 @@ export default {
return
}
const res = await uni.$api.evaluationApi.evalOrderOwnerReQuote(this.requoteObj)
console.log('res:', res)
if (res.data.code == 0) {
uni.showToast({
title: '重新报价成功',
title: '重新报价已提交,请等待报价更新',
icon: 'none',
duration: 3000
})
this.$refs.requotePopup.closePopup()
this.currentPage = 1
this.search()
setTimeout(() => {
this.currentPage = 1
this.search()
}, 500)
} else {
uni.hideLoading()
uni.showToast({
......
import config from './ossUploadFile/config.js'
import base64 from './ossUploadFile/base64.js'
import Hmac from './ossUploadFile/hmac.js'
import Sha1 from './ossUploadFile/sha1.js'
import Crypto from './ossUploadFile/crypto.js'
/**
* 上传文件到阿里云oss
* @param {string} file 图片信息
* @param {string} dir 表示要传到哪个目录下
* @return 完整的图片地址
*/
const uploadFile = function (file, filePath) {
console.log('上传文件到阿里云oss', file, filePath)
return new Promise(async (resolve, reject) => {
// 添加文件大小限制检查
if (file && file.size) {
// 定义文件类型和大小限制
const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
const videoTypes = ['mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv']
// 提取文件后缀
const fileExtension = file ? (file.name ? file.name.split('.').pop().toLowerCase() : file.path.split('.').pop().toLowerCase()) : filePath.split('.').pop().toLowerCase()
// 检查文件大小
const fileSizeMB = file.size / (1024 * 1024) // 转换为MB
// 图片文件大小限制10MB
if (imageTypes.includes(fileExtension) && fileSizeMB > 10) {
uni.showToast({
title: '图片上传最大10MB',
icon: 'none'
})
reject(new Error('图片上传最大10MB'))
return
}
// 视频文件大小限制100MB
if (videoTypes.includes(fileExtension) && fileSizeMB > 100) {
uni.showToast({
title: '视频上传最大100MB',
icon: 'none'
})
reject(new Error('视频上传最大100MB'))
return
}
}
// 提取文件后缀
const fileExtension = file ? (file.name ? file.name.split('.').pop().toLowerCase() : file.path.split('.').pop().toLowerCase()) : filePath.split('.').pop().toLowerCase()
// 生成随机数(使用时间戳+随机字符串)
const timestamp = Date.now()
const randomStr = Math.random().toString(36).substring(2, 10)
const randomNum = timestamp + '_' + randomStr
let aliyunFileKey = config.folder + randomNum + '.' + fileExtension
console.log(aliyunFileKey, 'aliyunFileKey')
const aliyunServerURL = config.uploadUrl // OSS地址
const policyBase64 = getPolicyBase64()
const { signature, securityToken, lsaccessKeyId } = await getSignature(policyBase64) // 获取签名
uni.uploadFile({
url: aliyunServerURL, // 开发者服务器url
filePath: filePath, // 要上传文件资源的路径
name: 'file', // 必须填file
formData: {
key: aliyunFileKey,
policy: policyBase64,
OSSAccessKeyId: lsaccessKeyId,
success_action_status: '200', // 让服务端返回200, 不然默认会返回204
signature: signature,
'x-oss-security-token': securityToken // 使用STS签名时必传。
},
success: function (res) {
console.log(res, 444)
if (res.statusCode != 200) {
reject(
new Error(
'上传错误:' +
JSON.stringify({
statusCode: res.statusCode,
file: file,
key: aliyunFileKey,
policy: policyBase64,
OSSAccessKeyId: lsaccessKeyId,
signature: signature,
'x-oss-security-token': securityToken
})
)
)
} else {
uni.removeSavedFile({
file: file,
complete: function (res) {
console.log(res)
}
})
}
resolve(aliyunServerURL + aliyunFileKey)
},
fail: function (err) {
console.log(err, 555)
err.domainName = aliyunServerURL
reject(err)
}
})
})
}
const getPolicyBase64 = function () {
let date = new Date()
date.setHours(date.getHours() + config.timeout)
let srcT = date.toISOString()
const policyText = {
expiration: srcT, //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了
conditions: [
['content-length-range', 0, 1024 * 1024 * 1024] // 设置上传文件的大小限制(5m)
]
}
const policyBase64 = base64.encode(JSON.stringify(policyText))
return policyBase64
}
const getOssToken = async function () {
console.log('getOssToken')
const { lsaccessKeySecret, securityToken, lsaccessKeyId } = await uni.$api.commonApi.getToken({})
return {
lsaccessKeySecret,
securityToken,
lsaccessKeyId
}
}
// 生成签名
const getSignature = function (policyBase64) {
return new Promise(async reslove => {
const result = uni.$api.commonApi.getToken({}).then(res => {
const { lsaccessKeySecret, securityToken, lsaccessKeyId } = res
const bytes = Crypto.HmacSHA1(policyBase64, lsaccessKeySecret)
const signature = Crypto.enc.Base64.stringify(bytes)
reslove({
signature,
securityToken,
lsaccessKeyId
})
})
})
}
module.exports = { uploadFile }
......@@ -7,11 +7,11 @@
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
// base64,Hmac,Sha1,Crypto 相关算法
import config from "./config.js";
import base64 from "./base64.js";
import Hmac from "./hmac.js";
import Sha1 from "./sha1.js";
import Crypto from "./crypto.js";
import config from './config.js'
import base64 from './base64.js'
import Hmac from './hmac.js'
import Sha1 from './sha1.js'
import Crypto from './crypto.js'
/**
* 上传文件到阿里云oss
* @param {string} filePath 图片的本地资源路径
......@@ -19,44 +19,44 @@ import Crypto from "./crypto.js";
* @return 完整的图片地址
*/
const uploadFile = function (filePath) {
console.log('上传文件到阿里云oss', filePath)
return new Promise(async (resolve, reject) => {
if (!filePath || filePath.length < 9) {
uni.showModal({
title: "文件错误",
content: "请重试",
showCancel: false,
});
reject("文件错误");
title: '文件错误',
content: '请重试',
showCancel: false
})
reject('文件错误')
}
// 获取上传的文件类型
let fileTypeIndex = filePath.lastIndexOf("/");
let fileType = filePath.substring(fileTypeIndex + 1);
let aliyunFileKey = config.folder + fileType;
const aliyunServerURL = config.uploadUrl; // OSS地址
const accessid = config.OSSAccessKeyId;
const policyBase64 = getPolicyBase64();
const { signature, securityToken, lsaccessKeyId } = await getSignature(
policyBase64
); // 获取签名
let fileTypeIndex = filePath.lastIndexOf('/')
let fileType = filePath.substring(fileTypeIndex + 1)
console.log(fileType, '获取上传的文件类型')
let aliyunFileKey = config.folder + fileType
const aliyunServerURL = config.uploadUrl // OSS地址
const accessid = config.OSSAccessKeyId
const policyBase64 = getPolicyBase64()
const { signature, securityToken, lsaccessKeyId } = await getSignature(policyBase64) // 获取签名
uni.uploadFile({
url: aliyunServerURL, // 开发者服务器url
filePath: filePath, // 要上传文件资源的路径
name: "file", // 必须填file
name: 'file', // 必须填file
formData: {
key: aliyunFileKey,
policy: policyBase64,
OSSAccessKeyId: lsaccessKeyId,
success_action_status: "200", // 让服务端返回200, 不然默认会返回204
success_action_status: '200', // 让服务端返回200, 不然默认会返回204
signature: signature,
"x-oss-security-token": securityToken, // 使用STS签名时必传。
'x-oss-security-token': securityToken // 使用STS签名时必传。
},
success: function (res) {
console.log(res, 444);
console.log(res, 444)
if (res.statusCode != 200) {
reject(
new Error(
"上传错误:" +
'上传错误:' +
JSON.stringify({
statusCode: res.statusCode,
filePath,
......@@ -64,65 +64,64 @@ const uploadFile = function (filePath) {
policy: policyBase64,
OSSAccessKeyId: lsaccessKeyId,
signature: signature,
"x-oss-security-token": securityToken,
'x-oss-security-token': securityToken
})
)
);
)
} else {
uni.removeSavedFile({
filePath,
complete: function (res) {
console.log(res);
},
});
console.log(res)
}
})
}
resolve(aliyunServerURL + aliyunFileKey);
resolve(aliyunServerURL + aliyunFileKey)
},
fail: function (err) {
err.domainName = aliyunServerURL;
reject(err);
},
});
});
};
err.domainName = aliyunServerURL
reject(err)
}
})
})
}
const getPolicyBase64 = function () {
let date = new Date();
date.setHours(date.getHours() + config.timeout);
let srcT = date.toISOString();
let date = new Date()
date.setHours(date.getHours() + config.timeout)
let srcT = date.toISOString()
const policyText = {
expiration: srcT, //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了
conditions: [
["content-length-range", 0, 1024 * 1024 * 1024], // 设置上传文件的大小限制(5m)
],
};
const policyBase64 = base64.encode(JSON.stringify(policyText));
return policyBase64;
};
['content-length-range', 0, 1024 * 1024 * 1024] // 设置上传文件的大小限制(5m)
]
}
const policyBase64 = base64.encode(JSON.stringify(policyText))
return policyBase64
}
const getOssToken = async function () {
console.log("getOssToken");
const { lsaccessKeySecret, securityToken, lsaccessKeyId } =
await uni.$api.commonApi.getToken({});
console.log('getOssToken')
const { lsaccessKeySecret, securityToken, lsaccessKeyId } = await uni.$api.commonApi.getToken({})
return {
lsaccessKeySecret,
securityToken,
lsaccessKeyId,
};
};
lsaccessKeyId
}
}
// 生成签名
const getSignature = function (policyBase64) {
return new Promise(async (reslove) => {
const result = uni.$api.commonApi.getToken({}).then((res) => {
const { lsaccessKeySecret, securityToken, lsaccessKeyId } = res;
const bytes = Crypto.HmacSHA1(policyBase64, lsaccessKeySecret);
const signature = Crypto.enc.Base64.stringify(bytes);
return new Promise(async reslove => {
const result = uni.$api.commonApi.getToken({}).then(res => {
const { lsaccessKeySecret, securityToken, lsaccessKeyId } = res
const bytes = Crypto.HmacSHA1(policyBase64, lsaccessKeySecret)
const signature = Crypto.enc.Base64.stringify(bytes)
reslove({
signature,
securityToken,
lsaccessKeyId,
});
});
lsaccessKeyId
})
})
// const result = await uni.request({
// url: 'https://dj.test.glsx.com.cn/rop-dj-smartcarlife/router',
// data: {
......@@ -150,7 +149,7 @@ const getSignature = function (policyBase64) {
// })
// }
// })
});
};
})
}
module.exports = { uploadFile, getOssToken };
module.exports = { uploadFile, getOssToken }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!