Merge branch 'master' of http://192.168.1.26:3000/dianliang/dl_uniapp
# Conflicts: # pages/components/my-notice-item-tg.vue
This commit is contained in:
commit
1f5db03144
@ -160,4 +160,12 @@ export function queryListByUserId(params) {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
params: params
|
params: params
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function evaluateAdd(data) {
|
||||||
|
return request({
|
||||||
|
url: '/busi/evaluate',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -7,9 +7,9 @@
|
|||||||
</view>
|
</view>
|
||||||
</block>
|
</block>
|
||||||
</view>
|
</view>
|
||||||
<view>
|
<!-- <view>
|
||||||
<input class="input-tag" v-model="inputzy" type="text" :placeholder="placeholder" @confirm="confirm">
|
<input class="input-tag" v-model="inputzy" type="text" :placeholder="placeholder" @confirm="confirm">
|
||||||
</view>
|
</view> -->
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
@ -138,4 +138,4 @@
|
|||||||
line-height: 50upx;
|
line-height: 50upx;
|
||||||
font-size: 28upx;
|
font-size: 28upx;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"cos-js-sdk-v5": "^1.8.7",
|
||||||
"html2canvas": "^1.4.1",
|
"html2canvas": "^1.4.1",
|
||||||
"rich-text-parser": "^1.0.2"
|
"rich-text-parser": "^1.0.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -154,4 +154,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<!-- 操作按钮 -->
|
<!-- 操作按钮 -->
|
||||||
<view class="opt-button-box">
|
<view class="opt-button-box">
|
||||||
|
<view class="opt-item" v-if="item.signStatus=='已通过'" @click="evaluate(item)">评价</view>
|
||||||
<view class="opt-item" @click="goDetail(item)">查看详情</view>
|
<view class="opt-item" @click="goDetail(item)">查看详情</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -86,6 +87,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
evaluate(item) {
|
||||||
|
this.$tab.navigateTo('/pages/mine/set/evaluate?userType=01&toUserId=' + item.userId)
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 查看通告详情
|
* 查看通告详情
|
||||||
* @param {Object} item
|
* @param {Object} item
|
||||||
|
|||||||
@ -213,4 +213,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -80,11 +80,11 @@
|
|||||||
limit="9"></uni-file-picker>
|
limit="9"></uni-file-picker>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 提示窗示例 -->
|
<!-- 提示窗示例 -->
|
||||||
<uni-popup ref="alertDialog" type="dialog">
|
<uni-popup ref="alertDialog" type="dialog">
|
||||||
<uni-popup-dialog cancelText="取消" confirmText="创建" iconPath="/static/detail/card.png"
|
<uni-popup-dialog cancelText="取消" confirmText="创建" iconPath="/static/detail/card.png"
|
||||||
content="没有可选择的收货地址,请先创建" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
|
content="没有可选择的收货地址,请先创建" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
|
||||||
</uni-popup>
|
</uni-popup>
|
||||||
<view class="item-field" style="align-items: center;">
|
<view class="item-field" style="align-items: center;">
|
||||||
<view class="submit-box" @click="submitForm">提交</view>
|
<view class="submit-box" @click="submitForm">提交</view>
|
||||||
</view>
|
</view>
|
||||||
@ -113,14 +113,14 @@
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
uploadUrl: config.baseUrl+'/common/upload',
|
uploadUrl: config.baseUrl + '/common/upload',
|
||||||
headers: {},
|
headers: {},
|
||||||
//所有可选的平台
|
//所有可选的平台
|
||||||
range: [],
|
range: [],
|
||||||
sizeType: ['compressed'],
|
sizeType: ['compressed'],
|
||||||
//图片数组
|
//图片数组
|
||||||
fileList: [],
|
fileList: [],
|
||||||
imageUrl:[],
|
imageUrl: [],
|
||||||
//地址集合
|
//地址集合
|
||||||
addressList: [],
|
addressList: [],
|
||||||
//名片数据对象
|
//名片数据对象
|
||||||
@ -146,33 +146,33 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
dialogConfirm(){
|
dialogConfirm() {
|
||||||
this.$tab.navigateTo('/pages/mine/addr/addr-list')
|
this.$tab.navigateTo('/pages/mine/addr/addr-list')
|
||||||
},
|
},
|
||||||
|
|
||||||
dialogClose(){
|
dialogClose() {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**初始化数据*/
|
/**初始化数据*/
|
||||||
initData(id) {
|
initData(id) {
|
||||||
this.fileList = []
|
this.fileList = []
|
||||||
this.imageUrl = []
|
this.imageUrl = []
|
||||||
if (id) {
|
if (id) {
|
||||||
getBusiCardById({
|
getBusiCardById({
|
||||||
id: id
|
id: id
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
console.log(res.data, 133)
|
console.log(res.data, 133)
|
||||||
this.dataObj = res.data
|
this.dataObj = res.data
|
||||||
if (this.dataObj.image != null && this.dataObj.image != ''){
|
if (this.dataObj.image != null && this.dataObj.image != '') {
|
||||||
console.log(this.dataObj.image,'this.dataObj.image')
|
console.log(this.dataObj.image, 'this.dataObj.image')
|
||||||
this.imageUrl = this.dataObj.image.split(',')
|
this.imageUrl = this.dataObj.image.split(',')
|
||||||
this.imageUrl.map((item)=>{
|
this.imageUrl.map((item) => {
|
||||||
this.fileList.push({
|
this.fileList.push({
|
||||||
url:config.baseUrl + item
|
url: item
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
@ -213,9 +213,9 @@
|
|||||||
initAddress() {
|
initAddress() {
|
||||||
uniSelectList().then(res => {
|
uniSelectList().then(res => {
|
||||||
this.addressList = res.data
|
this.addressList = res.data
|
||||||
if (this.addressList.length == 0){
|
if (this.addressList.length == 0) {
|
||||||
this.$refs.alertDialog.open()
|
this.$refs.alertDialog.open()
|
||||||
}
|
}
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
@ -259,11 +259,11 @@
|
|||||||
toast("收货地址不能为空")
|
toast("收货地址不能为空")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.fileList.length == 0) {
|
if (this.fileList.length == 0) {
|
||||||
toast("证明材料不能为空")
|
toast("证明材料不能为空")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.dataObj.image = this.imageUrl.join(',');
|
this.dataObj.image = this.imageUrl.join(',');
|
||||||
applyBusiCard(this.dataObj).then(res => {
|
applyBusiCard(this.dataObj).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -288,10 +288,11 @@
|
|||||||
url: '',
|
url: '',
|
||||||
filePath: file.tempFilePaths[i]
|
filePath: file.tempFilePaths[i]
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
|
console.log('上传图片', res);
|
||||||
this.fileList.push({
|
this.fileList.push({
|
||||||
url: res.url
|
url: res.url
|
||||||
})
|
})
|
||||||
this.imageUrl.push(res.fileName)
|
this.imageUrl.push(res.fileName)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -300,12 +301,12 @@
|
|||||||
this.fileList.splice(index, 1);
|
this.fileList.splice(index, 1);
|
||||||
this.imageUrl.splice(index, 1);
|
this.imageUrl.splice(index, 1);
|
||||||
},
|
},
|
||||||
uploadSuccess(res, file) {
|
uploadSuccess(res, file) {
|
||||||
console.log('上传成功', res);
|
console.log('上传成功', res);
|
||||||
},
|
},
|
||||||
uploadFail(error, file) {
|
uploadFail(error, file) {
|
||||||
console.log('上传失败', error);
|
console.log('上传失败', error);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -244,9 +244,14 @@
|
|||||||
methods: {
|
methods: {
|
||||||
toggle(type, key) {
|
toggle(type, key) {
|
||||||
this.type = type
|
this.type = type
|
||||||
this.popupImgUrl = getStrData(key)
|
if (type == 'center') {
|
||||||
// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
|
//公众号跳转
|
||||||
this.$refs.popup.open(type)
|
wx.openOfficialAccountProfile({
|
||||||
|
username: 'tonggaokuaijie', // 此处填写公众号的微信号
|
||||||
|
success: res => {},
|
||||||
|
fail: res => {}
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getDetail() {
|
getDetail() {
|
||||||
queryDetail({
|
queryDetail({
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
你觉得参与本次通告体验如何?<text>(1-10分)</text>
|
你觉得参与本次通告体验如何?<text>(1-10分)</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="item-value">
|
<view class="item-value">
|
||||||
<uni-rate :max="10" :value="dataObj.rate" />
|
<uni-rate :max="10" :value="dataObj.score" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="item-field">
|
<view class="item-field">
|
||||||
@ -19,17 +19,18 @@
|
|||||||
<biner-input-tags @change="change" :selectlist='selectlist' :disabled='disabled'
|
<biner-input-tags @change="change" :selectlist='selectlist' :disabled='disabled'
|
||||||
:placeholder='placeholder'></biner-input-tags>
|
:placeholder='placeholder'></biner-input-tags>
|
||||||
<view class="item-dom-box">
|
<view class="item-dom-box">
|
||||||
<view class="item-dom" v-for="(item,index) in tips" @click="chooseObj(item)">{{item}}</view>
|
<view class="item-dom" v-for="(item,index) in tips" @click="chooseObj(item)">{{item.title}}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
<view class="line-row-bottom">
|
<view class="line-row-bottom">
|
||||||
<uni-data-checkbox @change="chooseBoxFun($event,'isRead')" multiple :localdata="readBookList" />
|
<uni-data-checkbox @change="changeAnonymous" multiple :localdata="readBookList" />
|
||||||
<text class="text-red">你的头像和昵称将在评价中隐藏</text>
|
<text class="text-red">你的头像和昵称将在评价中隐藏</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="item-field" style="align-items: center;">
|
<view class="item-field" style="align-items: center;">
|
||||||
<view class="submit-box" @click="submitForm">提交</view>
|
<view class="submit-box" @click="evaluateAddFun">提交</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -40,6 +41,12 @@
|
|||||||
import navigationBarVue from '@/components/navigation/navigationBar.vue';
|
import navigationBarVue from '@/components/navigation/navigationBar.vue';
|
||||||
// 引入biner-input-tags
|
// 引入biner-input-tags
|
||||||
import binerInputTags from '@/components/biner-input-tags/biner-input-tags'
|
import binerInputTags from '@/components/biner-input-tags/biner-input-tags'
|
||||||
|
import {
|
||||||
|
evaluateAdd
|
||||||
|
} from '@/api/business/notice';
|
||||||
|
import {
|
||||||
|
getCatgByCode
|
||||||
|
} from '@/api/system/config.js'
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
navigationBarVue,
|
navigationBarVue,
|
||||||
@ -49,28 +56,91 @@
|
|||||||
return {
|
return {
|
||||||
disabled: false, //不禁用
|
disabled: false, //不禁用
|
||||||
// 默认的数组 不填默认的是空数组
|
// 默认的数组 不填默认的是空数组
|
||||||
selectlist: [{
|
selectlist: [],
|
||||||
title: '专业'
|
|
||||||
}],
|
|
||||||
// 默认提示
|
// 默认提示
|
||||||
placeholder: '请输入评价',
|
placeholder: '请输入评价',
|
||||||
dataObj: {
|
dataObj: {
|
||||||
rate: 0,
|
score: 0,
|
||||||
|
toUserId: null,
|
||||||
|
userType: null,
|
||||||
|
isAnonymous: '0'
|
||||||
},
|
},
|
||||||
tips: ["定人快", "审稿快", "提现快"],
|
tips: [],
|
||||||
readBookList: [{
|
readBookList: [{
|
||||||
text: '匿名评价',
|
text: '匿名评价',
|
||||||
value: true
|
value: '1'
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onLoad(option) {
|
||||||
|
this.dataObj.toUserId = option.toUserId
|
||||||
|
this.dataObj.userType = option.userType
|
||||||
|
this.dataObj.userType = option.userType
|
||||||
|
if (option.userType == '01') {
|
||||||
|
option.toUserType = '02'
|
||||||
|
} else {
|
||||||
|
option.toUserType = '01'
|
||||||
|
}
|
||||||
|
this.initData("plfl", "tips")
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
|
changeAnonymous(data) {
|
||||||
|
console.log(data, 82);
|
||||||
|
if (data.detail.data && data.detail.data.length > 0) {
|
||||||
|
this.dataObj.isAnonymous = '1'
|
||||||
|
} else {
|
||||||
|
this.dataObj.isAnonymous = '0'
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 初始化数据
|
||||||
|
* @param {Object} code
|
||||||
|
* @param {Object} dataObj
|
||||||
|
*/
|
||||||
|
initData(code, dataObj) {
|
||||||
|
let that = this
|
||||||
|
getCatgByCode({
|
||||||
|
code: code
|
||||||
|
}).then(res => {
|
||||||
|
if (res.code == 200) {
|
||||||
|
this[dataObj] = res.data
|
||||||
|
}
|
||||||
|
}).catch((e) => {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'error',
|
||||||
|
duration: 2000,
|
||||||
|
title: e
|
||||||
|
});
|
||||||
|
})
|
||||||
|
},
|
||||||
|
evaluateAddFun() {
|
||||||
|
this.dataObj.evaluate = ''
|
||||||
|
if (this.selectlist && this.selectlist.length > 0) {
|
||||||
|
this.selectlist.forEach(it => {
|
||||||
|
this.dataObj.evaluate = this.dataObj.evaluate + it.title + ','
|
||||||
|
})
|
||||||
|
this.dataObj.evaluate = this.dataObj.evaluate.slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
evaluateAdd(this.dataObj).then(res => {
|
||||||
|
uni.showToast({
|
||||||
|
title: '评价成功',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 1000
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.navigateBack()
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
|
})
|
||||||
|
},
|
||||||
// 监听变化的数据
|
// 监听变化的数据
|
||||||
change(arr) {
|
change(arr) {
|
||||||
this.selectlist = arr
|
this.selectlist = arr
|
||||||
},
|
},
|
||||||
/**提交*/
|
|
||||||
submitForm() {},
|
|
||||||
/**
|
/**
|
||||||
* 去我的建议列表
|
* 去我的建议列表
|
||||||
*/
|
*/
|
||||||
@ -79,7 +149,8 @@
|
|||||||
},
|
},
|
||||||
chooseObj(item) {
|
chooseObj(item) {
|
||||||
this.selectlist.push({
|
this.selectlist.push({
|
||||||
title: item
|
title: item.title,
|
||||||
|
code: item.code
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,10 +16,7 @@
|
|||||||
<text v-else-if="0==item.approvalStatus" style="color:#FC1F3E ;">审核中</text>
|
<text v-else-if="0==item.approvalStatus" style="color:#FC1F3E ;">审核中</text>
|
||||||
<text v-else>未通过</text>
|
<text v-else>未通过</text>
|
||||||
</view> -->
|
</view> -->
|
||||||
<view class="edit-text">
|
|
||||||
<text v-if="!item.ifChecked" style="color:#F97A35;">待定</text>
|
|
||||||
<text v-else style="color:#5986F2 ;" @click="chooseOk(item)">合适</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
<view class="card-content">
|
<view class="card-content">
|
||||||
<view class="card-person-info">
|
<view class="card-person-info">
|
||||||
@ -42,6 +39,8 @@
|
|||||||
</view>
|
</view>
|
||||||
<view v-if="status==0" :class="['edit-dom']" @click="chooseCardVal(item.id)">{{"合适"}}
|
<view v-if="status==0" :class="['edit-dom']" @click="chooseCardVal(item.id)">{{"合适"}}
|
||||||
</view>
|
</view>
|
||||||
|
<view v-else :class="['edit-dom']" @click="evaluate(item)">{{"评价"}}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -77,6 +76,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
evaluate(item) {
|
||||||
|
this.$tab.navigateTo('/pages/mine/set/evaluate?userType=02&toUserId=' + item.userId)
|
||||||
|
},
|
||||||
chooseItem() {
|
chooseItem() {
|
||||||
console.log(this.dataList, "dataList")
|
console.log(this.dataList, "dataList")
|
||||||
this.$emit("updateList", this.dataList)
|
this.$emit("updateList", this.dataList)
|
||||||
@ -91,7 +93,23 @@
|
|||||||
* 去名片所有者主页
|
* 去名片所有者主页
|
||||||
*/
|
*/
|
||||||
goIndex(item) {
|
goIndex(item) {
|
||||||
this.$emit("goIndex", item)
|
uni.setClipboardData({
|
||||||
|
data: item.indexUrl,
|
||||||
|
success: function() {
|
||||||
|
uni.showToast({
|
||||||
|
title: '主页链接复制成功,请到应用中访问',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail: function() {
|
||||||
|
uni.showToast({
|
||||||
|
title: '复制失败',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 将名片置为合适或不合适
|
* 将名片置为合适或不合适
|
||||||
@ -243,4 +261,4 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -253,7 +253,7 @@
|
|||||||
viewMy: false,
|
viewMy: false,
|
||||||
//通告ID
|
//通告ID
|
||||||
noticeId: null,
|
noticeId: null,
|
||||||
imageUrl: config.baseUrl,
|
imageUrl: '',
|
||||||
//是否显示下方操作按钮--刚开始不显示
|
//是否显示下方操作按钮--刚开始不显示
|
||||||
showBottom: false,
|
showBottom: false,
|
||||||
//当前用户
|
//当前用户
|
||||||
|
|||||||
11083
utils/cos-wx-sdk-v5.js
Normal file
11083
utils/cos-wx-sdk-v5.js
Normal file
File diff suppressed because one or more lines are too long
42
utils/cos.js
Normal file
42
utils/cos.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import config from '@/config'
|
||||||
|
const COS = require('./cos-wx-sdk-v5.js'); // 开发时使用
|
||||||
|
// const COS = require('./lib/cos-wx-sdk-v5.min.js'); // 上线时使用压缩包
|
||||||
|
|
||||||
|
const baseUrl = config.baseUrl
|
||||||
|
|
||||||
|
const cos = new COS({
|
||||||
|
SimpleUploadMethod: 'putObject', // 强烈建议,高级上传、批量上传内部对小文件做简单上传时使用putObject,sdk版本至少需要v1.3.0
|
||||||
|
getAuthorization: function(options, callback) {
|
||||||
|
// 初始化时不会调用,只有调用 cos 方法(例如 cos.putObject)时才会进入
|
||||||
|
// 异步获取临时密钥
|
||||||
|
// 服务端 JS 示例:https://github.com/tencentyun/cos-js-sdk-v5/blob/master/server/
|
||||||
|
// 服务端其他语言参考 COS STS SDK :https://github.com/tencentyun/qcloud-cos-sts-sdk
|
||||||
|
// STS 详细文档指引看:https://cloud.tencent.com/document/product/436/14048
|
||||||
|
const stsUrl = baseUrl + '/cos/sts'; // stsUrl 替换成您自己的后端服务
|
||||||
|
wx.request({
|
||||||
|
url: stsUrl,
|
||||||
|
data: {
|
||||||
|
bucket: options.Bucket,
|
||||||
|
region: options.Region,
|
||||||
|
},
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(result) {
|
||||||
|
const data = result.data;
|
||||||
|
const credentials = data && data.credentials;
|
||||||
|
if (!data || !credentials) return console.error('credentials invalid');
|
||||||
|
// 检查 credentials 格式
|
||||||
|
console.log(credentials);
|
||||||
|
callback({
|
||||||
|
TmpSecretId: credentials.tmpSecretId,
|
||||||
|
TmpSecretKey: credentials.tmpSecretKey,
|
||||||
|
// v1.2.0之前版本的 SDK 使用 XCosSecurityToken 而不是 SecurityToken
|
||||||
|
SecurityToken: credentials.sessionToken,
|
||||||
|
// 建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
|
||||||
|
StartTime: data.startTime, // 时间戳,单位秒,如:1580000000
|
||||||
|
ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
export default cos;
|
||||||
105
utils/upload.js
105
utils/upload.js
@ -1,70 +1,41 @@
|
|||||||
import store from '@/store'
|
import cos from '@/utils/cos' // 您已有的COS实例
|
||||||
import config from '@/config'
|
import {
|
||||||
import { getToken } from '@/utils/auth'
|
getToken
|
||||||
import errorCode from '@/utils/errorCode'
|
} from '@/utils/auth'
|
||||||
import { toast, showConfirm, tansParams } from '@/utils/common'
|
import {
|
||||||
|
toast
|
||||||
|
} from '@/utils/common'
|
||||||
|
|
||||||
let timeout = 10000
|
|
||||||
const baseUrl = config.baseUrl
|
|
||||||
|
|
||||||
const upload = config => {
|
const upload = async (config) => {
|
||||||
// 是否需要设置 token
|
try {
|
||||||
const isToken = (config.headers || {}).isToken === false
|
console.log('config', config);
|
||||||
config.header = config.header || {}
|
// 生成文件名(避免中文乱码)
|
||||||
if (getToken() && !isToken) {
|
const fileName = '/images/' + config.filePath.split('/').pop(); // 提取最后一段路径
|
||||||
config.header['Authorization'] = 'Bearer ' + getToken()
|
const data = await cos.uploadFile({
|
||||||
}
|
Bucket: 'notice-1348525010', // 填写自己的 bucket,必须字段
|
||||||
// get请求映射params参数
|
Region: 'ap-beijing', // 存储桶所在地域,必须字段
|
||||||
if (config.params) {
|
Key: fileName,
|
||||||
let url = config.url + '?' + tansParams(config.params)
|
FilePath: config.filePath,
|
||||||
url = url.slice(0, -1)
|
/* v1.4.3之前的版本必须,v1.4.3及以后的版本非必须 */
|
||||||
config.url = url
|
SliceSize: 1024 * 1024 * 5, // 触发分块上传的阈值,超过5MB 使用分块上传,小于5MB使用简单上传。可自行设置,非必须
|
||||||
}
|
onProgress: function(progressData) {
|
||||||
return new Promise((resolve, reject) => {
|
console.log('上传进度:', progressData);
|
||||||
uni.uploadFile({
|
},
|
||||||
timeout: config.timeout || timeout,
|
// onTaskReady: function(id) { // 非必须
|
||||||
url: baseUrl + '/common/upload' + config.url,
|
// taskId = id;
|
||||||
filePath: config.filePath,
|
// },
|
||||||
name: config.name || 'file',
|
});
|
||||||
header: config.header,
|
console.log('上传成功', data);
|
||||||
formData: config.formData,
|
// 上传成功
|
||||||
success: (res) => {
|
const fileUrl = `https://${data.Location}`;
|
||||||
let result = JSON.parse(res.data)
|
return {
|
||||||
const code = result.code || 200
|
url: fileUrl,
|
||||||
const msg = errorCode[code] || result.msg || errorCode['default']
|
fileName: fileUrl
|
||||||
if (code === 200) {
|
}
|
||||||
resolve(result)
|
} catch (e) {
|
||||||
} else if (code == 401) {
|
console.error('上传失败', e);
|
||||||
showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => {
|
}
|
||||||
if (res.confirm) {
|
|
||||||
store.dispatch('LogOut').then(res => {
|
|
||||||
uni.reLaunch({ url: '/pages/login/login' })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
reject('无效的会话,或者会话已过期,请重新登录。')
|
|
||||||
} else if (code === 500) {
|
|
||||||
toast(msg)
|
|
||||||
reject('500')
|
|
||||||
} else if (code !== 200) {
|
|
||||||
toast(msg)
|
|
||||||
reject(code)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fail: (error) => {
|
|
||||||
let { message } = error
|
|
||||||
if (message == 'Network Error') {
|
|
||||||
message = '后端接口连接异常'
|
|
||||||
} else if (message.includes('timeout')) {
|
|
||||||
message = '系统接口请求超时'
|
|
||||||
} else if (message.includes('Request failed with status code')) {
|
|
||||||
message = '系统接口' + message.substr(message.length - 3) + '异常'
|
|
||||||
}
|
|
||||||
toast(message)
|
|
||||||
reject(error)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
// 明确导出类型
|
||||||
export default upload
|
export default upload
|
||||||
Loading…
Reference in New Issue
Block a user