例一:
methods:{
before (file) {
console.log('文件', file)
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
// 图片转base64完成后返回reader对象
//this.smallbase64 = reader.result;
console.log('文件2', reader.result)
resolve(reader.result);
};
});
},
async upload (item) {
console.log(item)
this.addBook.coverUrl = await this.before(item.raw);
let parames = {
functionName: "productbiz.service.puhui.UpdatePictureService",
methodName: "uploadImage",
data: {
coverImage: this.addBook.coverUrl,
userId: JSON.parse(sessionStorage.getItem('sessionData')).userId
}
};
console.log(222, parames);
this.http(JSON.stringify(parames))
.then(res => {
console.log(res.data.path)
this.addBook.coverUrl = res.data.path
})
.catch(res => { });
},
}
例二:
getSelectTemplateInfo(id) {
// 获得模板详细信息
return new Promise(resolve => {
let parames = {
functionName: "marketingTemplateService",
methodName: "selectMarketingTemplateInfo",
pageNo: 1,
pageSize: 10,
originSource: {
OS: this.OS,
version: "h5_v2.0"
},
data: {
templateId: id
}
};
this.$post(JSON.stringify(parames)).then(result => {
if (result.errorCode == ERROR_CODE && result.data.codeType == 200) {
// console.log('详情',result.data.templateInfo)
resolve(result.data.templateInfo);
}
});
});
},
async selectTemplate(item, index) {
let info = await this.getSelectTemplateInfo(item.id);
if (this.selectedTempProduct == null) {
// 未选择产品
this.SET_SELECTEDTEMP(info);
this.selectedTempIndex = index;
console.log("选中模板", index, this.selectedTemp);
} else {
// 选择产品后切换模板判断模板类型
if (this.selectedTempProduct.productType != item.prdType) {
Dialog.confirm({
// title: "选择产品提示",
confirmButtonText: "确定",
confirmButtonColor: "#DE1716",
width: "288",
className: "confirmStyle",
message: "您选择的产品不适用于该模板,切换后需要重新选择产品"
})
.then(() => {
this.clearProduct();
this.SET_SELECTEDTEMP(info);
this.selectedTempIndex = index;
})
.catch(() => {
console.log("取消");
});
}else{
this.SET_SELECTEDTEMP(info);
this.selectedTempIndex = index;
}
console.log("选中模板", index, this.selectedTemp);
}
},