|
@@ -1,3 +1,7 @@
|
|
|
+import {
|
|
|
+ ApiModel
|
|
|
+} from "../../../utils/api";
|
|
|
+const _Http = new ApiModel();
|
|
|
Page({
|
|
|
data: {
|
|
|
formats: {},
|
|
@@ -5,14 +9,20 @@ Page({
|
|
|
placeholder: '开始输入...',
|
|
|
editorHeight: 300,
|
|
|
keyboardHeight: 0,
|
|
|
- isIOS: false
|
|
|
+ isIOS: false,
|
|
|
+ showRichText: '', //富文本文件
|
|
|
},
|
|
|
readOnlyChange() {
|
|
|
this.setData({
|
|
|
readOnly: !this.data.readOnly
|
|
|
})
|
|
|
},
|
|
|
- onLoad() {
|
|
|
+ onLoad(options) {
|
|
|
+ console.log(options)
|
|
|
+ this.setData({
|
|
|
+ showRichText: "<p>asdasdsdgss<img src=\"https://bwj.obs.cn-east-2.myhuaweicloud.com:443/202201061641468934405B8cac64d.png\" width=\"80%\" data-custom=\"id=535&role=god\"></p><p><br></p>"
|
|
|
+ })
|
|
|
+
|
|
|
const platform = wx.getSystemInfoSync().platform
|
|
|
const isIOS = platform === 'ios'
|
|
|
this.setData({
|
|
@@ -63,12 +73,18 @@ Page({
|
|
|
onEditorReady() {
|
|
|
const that = this
|
|
|
wx.createSelectorQuery().select('#editor').context(function (res) {
|
|
|
+ console.log(res)
|
|
|
that.editorCtx = res.context
|
|
|
+ that.editorCtx.setContents({
|
|
|
+ html: that.data.showRichText //将数据写入编辑器内
|
|
|
+ })
|
|
|
+ event.on('resetEditor', that, that.onEditorReady.bind(that))
|
|
|
}).exec()
|
|
|
+
|
|
|
},
|
|
|
- asd54(e) {
|
|
|
+ compileText(e) {
|
|
|
this.setData({
|
|
|
- htmlT: e.detail.html
|
|
|
+ showRichText: e.detail.html
|
|
|
})
|
|
|
},
|
|
|
blur() {
|
|
@@ -115,22 +131,84 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
insertImage() {
|
|
|
- const that = this
|
|
|
+ const that = this;
|
|
|
wx.chooseImage({
|
|
|
count: 1,
|
|
|
success: function (res) {
|
|
|
- that.editorCtx.insertImage({
|
|
|
- src: res.tempFilePaths[0],
|
|
|
- data: {
|
|
|
- id: 'abcd',
|
|
|
- role: 'god'
|
|
|
+ console.log(res)
|
|
|
+ //获取文件后缀
|
|
|
+ var index = res.tempFiles[0].path.lastIndexOf(".");
|
|
|
+ var ext = res.tempFiles[0].path.substr(index + 1);
|
|
|
+ //文件名称
|
|
|
+ const timestamp = Date.parse(new Date());;
|
|
|
+ //发送请求
|
|
|
+ wx.getFileSystemManager().readFile({
|
|
|
+ filePath: res.tempFiles[0].path,
|
|
|
+ success: result => {
|
|
|
+ console.log("临时路径", result)
|
|
|
+ //返回临时文件路径
|
|
|
+ const fileData = result.data
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.system.docManage",
|
|
|
+ "method": "getFileName",
|
|
|
+ "content": {
|
|
|
+ "filename": timestamp,
|
|
|
+ "filetype": ext,
|
|
|
+ "ownertable": "tagents",
|
|
|
+ "ownerid": wx.getStorageSync('userData').tagentsid,
|
|
|
+ "ftype": "richtext"
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("上传成功", res)
|
|
|
+ if (res.msg != "成功") return wx.showToast({
|
|
|
+ title: "文件上传失败,请稍后再试",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ that.uploadFile(res, fileData)
|
|
|
+ }).catch(err => {})
|
|
|
},
|
|
|
- width: '80%',
|
|
|
- success: function () {
|
|
|
- console.log('insert image success')
|
|
|
+ fail: console.error
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 上传成功反馈 */
|
|
|
+ uploadFile(res, data) {
|
|
|
+ console.log("文件上传")
|
|
|
+ var that = this;
|
|
|
+ wx.request({
|
|
|
+ url: res.data.obsuploadurl,
|
|
|
+ method: "PUT",
|
|
|
+ data: data,
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/octet-stream' // 默认值
|
|
|
+ },
|
|
|
+ success() {
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.system.docManage",
|
|
|
+ "method": "uploadSuccess",
|
|
|
+ "content": {
|
|
|
+ "obsfilename": res.data.obsfilename
|
|
|
}
|
|
|
+ }).then(res => {
|
|
|
+ console.log("上传成功反馈", res)
|
|
|
+ that.editorCtx.insertImage({
|
|
|
+ src: res.data[0].fobsurl,
|
|
|
+ data: {
|
|
|
+ id: res.data[0].tattachmentid,
|
|
|
+ role: 'god'
|
|
|
+ },
|
|
|
+ width: '80%',
|
|
|
+ success: function () {
|
|
|
+ console.log('insert image success')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err)
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
- }
|
|
|
+ },
|
|
|
})
|