|
|
|
@ -139,7 +139,7 @@ |
|
|
|
:adjust-position="false" :cursor-spacing="160" @focus="focusFormField('startPayNumField')" @blur="blurFormField"> |
|
|
|
</uni-forms-item> |
|
|
|
</view> |
|
|
|
<uni-forms-item label="详细图文" name="startPayNum"> |
|
|
|
<uni-forms-item label="详细图文" name="productIntro"> |
|
|
|
<view class="xiangxi-box"> |
|
|
|
<sp-editor |
|
|
|
@init="initEditor" |
|
|
|
@ -216,6 +216,9 @@ |
|
|
|
moreBuyProductOptions:[], |
|
|
|
scrollTarget:'', |
|
|
|
editorIns: null, |
|
|
|
editorReady: false, |
|
|
|
editorTouched: false, |
|
|
|
settingEditor: false, |
|
|
|
typeItem: {}, |
|
|
|
shopMerchantType:0, |
|
|
|
formData: { |
|
|
|
@ -323,7 +326,13 @@ |
|
|
|
* @param {Object} e {html,text} 内容的html文本,和text文本 |
|
|
|
*/ |
|
|
|
inputOver(e) { |
|
|
|
this.productIntro = e |
|
|
|
if (this.settingEditor) return |
|
|
|
const html = e && typeof e === 'object' ? (e.html || '') : (e || '') |
|
|
|
const text = e && typeof e === 'object' && e.text ? String(e.text).replace(/[\s\u00a0]/g, '') : '' |
|
|
|
if (!this.editorReady && !html && !text) return |
|
|
|
if (!html && !text && this.formData.productIntro && !this.editorTouched) return |
|
|
|
this.editorTouched = true |
|
|
|
this.formData.productIntro = html |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 超出最大内容限制 |
|
|
|
@ -340,9 +349,37 @@ |
|
|
|
* @tutorial 相关api https://uniapp.dcloud.net.cn/api/media/editor-context.html |
|
|
|
*/ |
|
|
|
initEditor(editor) { |
|
|
|
this.editorIns = editor // 保存编辑器实例 |
|
|
|
// 保存编辑器实例后,可以在此处获取后端数据,并赋值给编辑器初始化内容 |
|
|
|
|
|
|
|
this.editorIns = editor |
|
|
|
this.editorReady = true |
|
|
|
this.setEditorContent(this.formData.productIntro) |
|
|
|
}, |
|
|
|
setEditorContent(html) { |
|
|
|
if (!this.editorIns || html === undefined || html === null || html === '') return |
|
|
|
this.settingEditor = true |
|
|
|
this.editorIns.setContents({ |
|
|
|
html: html |
|
|
|
}) |
|
|
|
setTimeout(() => { |
|
|
|
this.settingEditor = false |
|
|
|
}, 300) |
|
|
|
}, |
|
|
|
syncProductIntro() { |
|
|
|
return new Promise((resolve) => { |
|
|
|
if (!this.editorIns || typeof this.editorIns.getContents !== 'function') { |
|
|
|
resolve() |
|
|
|
return |
|
|
|
} |
|
|
|
this.editorIns.getContents({ |
|
|
|
success: (res) => { |
|
|
|
const html = res && res.html ? res.html : '' |
|
|
|
if (html || this.editorTouched) { |
|
|
|
this.formData.productIntro = html |
|
|
|
} |
|
|
|
resolve() |
|
|
|
}, |
|
|
|
fail: () => resolve() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 直接运行示例工程插入图片无法正常显示的看这里 |
|
|
|
@ -352,53 +389,51 @@ |
|
|
|
* @param {Object} editorCtx |
|
|
|
*/ |
|
|
|
upinImage(tempFiles, editorCtx) { |
|
|
|
/** |
|
|
|
* 本地临时插入图片预览 |
|
|
|
* 注意:这里仅是示例本地图片预览,因为需要将图片先上传到云端,再将图片插入到编辑器中 |
|
|
|
* 正式开发时,还请将此处注释,并解开下面 使用 uniCloud.uploadFile 上传图片的示例方法 的注释 |
|
|
|
* @tutorial https://uniapp.dcloud.net.cn/api/media/editor-context.html#editorcontext-insertimage |
|
|
|
*/ |
|
|
|
// #ifdef MP-WEIXIN |
|
|
|
// 注意微信小程序的图片路径是在tempFilePath字段中 |
|
|
|
editorCtx.insertImage({ |
|
|
|
src: tempFiles[0].tempFilePath, |
|
|
|
width: '80%', // 默认不建议铺满宽度100%,预留一点空隙以便用户编辑 |
|
|
|
success: function() {} |
|
|
|
}) |
|
|
|
// #endif |
|
|
|
|
|
|
|
// #ifndef MP-WEIXIN |
|
|
|
editorCtx.insertImage({ |
|
|
|
src: tempFiles[0].path, |
|
|
|
width: '80%', // 默认不建议铺满宽度100%,预留一点空隙以便用户编辑 |
|
|
|
success: function() {} |
|
|
|
const files = Array.isArray(tempFiles) ? tempFiles : [] |
|
|
|
files.forEach((item) => { |
|
|
|
const filePath = item.tempFilePath || item.path |
|
|
|
if (!filePath) return |
|
|
|
uni.showLoading({ |
|
|
|
title: '上传中', |
|
|
|
mask: true |
|
|
|
}) |
|
|
|
uni.uploadFile({ |
|
|
|
url: getApp().globalData.mainurl + '/upload/file', |
|
|
|
filePath: filePath, |
|
|
|
name: 'file', |
|
|
|
header: { |
|
|
|
"content-type": "multipart/form-data", |
|
|
|
'accessToken': uni.getStorageSync("hiver_token") |
|
|
|
}, |
|
|
|
success: (uploadFileRes) => { |
|
|
|
uni.hideLoading() |
|
|
|
let pathData = {} |
|
|
|
try { |
|
|
|
pathData = JSON.parse(uploadFileRes.data || '{}') |
|
|
|
} catch (e) { |
|
|
|
pathData = {} |
|
|
|
} |
|
|
|
if (!pathData.result) { |
|
|
|
uni.showToast({ |
|
|
|
title: pathData.message || '图片上传失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
editorCtx.insertImage({ |
|
|
|
src: pathData.result, |
|
|
|
width: '80%' |
|
|
|
}) |
|
|
|
}, |
|
|
|
fail: () => { |
|
|
|
uni.hideLoading() |
|
|
|
uni.showToast({ |
|
|
|
title: '图片上传失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
// #endif |
|
|
|
|
|
|
|
/** |
|
|
|
* 使用 uniCloud.uploadFile 上传图片的示例方法(可适用多选上传) |
|
|
|
* 正式开发环境中,请将上面 本地临时插入图片预览 注释后,模仿以下写法 |
|
|
|
*/ |
|
|
|
// tempFiles.forEach(async (item) => { |
|
|
|
// uni.showLoading({ |
|
|
|
// title: '上传中请稍后', |
|
|
|
// mask: true |
|
|
|
// }) |
|
|
|
// let upfile = await uniCloud.uploadFile({ |
|
|
|
// filePath: item.path, |
|
|
|
// // 同名会导致报错 policy_does_not_allow_file_overwrite |
|
|
|
// // cloudPath可由 想要存储的文件夹/文件名 拼接,若不拼文件夹名则默认存储在cloudstorage文件夹中 |
|
|
|
// cloudPath: `cloudstorage/${item.name}`, |
|
|
|
// cloudPathAsRealPath: true |
|
|
|
// }) |
|
|
|
// editorCtx.insertImage({ |
|
|
|
// src: upfile.fileID, |
|
|
|
// width: '80%', // 默认不建议铺满宽度100%,预留一点空隙以便用户编辑 |
|
|
|
// success: function () { |
|
|
|
// uni.hideLoading() |
|
|
|
// } |
|
|
|
// }) |
|
|
|
// }) |
|
|
|
}, |
|
|
|
//跳转分类页 |
|
|
|
goGategoryLow() { |
|
|
|
@ -457,7 +492,7 @@ |
|
|
|
} |
|
|
|
}, |
|
|
|
// 触发提交表单 |
|
|
|
submit() { |
|
|
|
async submit() { |
|
|
|
let that = this; |
|
|
|
this.syncLunchBoxByMoreBuy() |
|
|
|
if (!this.validateRequiredProductFields()) { |
|
|
|
@ -472,6 +507,7 @@ |
|
|
|
if (!this.validateGroupBuyPrices()) { |
|
|
|
return |
|
|
|
} |
|
|
|
await this.syncProductIntro() |
|
|
|
// this.$refs.form.validate((valid) => { |
|
|
|
// if (valid) { |
|
|
|
if (this.modalType == 0) { |
|
|
|
@ -925,6 +961,7 @@ |
|
|
|
if (!this.isMoreBuyEnabled()) { |
|
|
|
this.getMoreBuyProductOptions() |
|
|
|
} |
|
|
|
this.setEditorContent(this.formData.productIntro) |
|
|
|
this.modalVisible = true; |
|
|
|
}, |
|
|
|
checkSpecValue(index){ |
|
|
|
@ -1418,8 +1455,10 @@ |
|
|
|
} |
|
|
|
.xiangxi-box{ |
|
|
|
flex: 1; |
|
|
|
height: 560rpx; |
|
|
|
border: 1px solid #eee; |
|
|
|
border-radius: 20rpx; |
|
|
|
overflow: hidden; |
|
|
|
} |
|
|
|
.left-box { |
|
|
|
width: 100%; |
|
|
|
|