Skip to content

Commit

Permalink
Merge pull request #497 from TwoKe945/master
Browse files Browse the repository at this point in the history
fix: 修复editable插件在点击换图时,出现的domain前缀未添加的问题
  • Loading branch information
jin-yufeng authored Mar 24, 2023
2 parents c0b780b + 380c674 commit ca66d5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 8 additions & 5 deletions plugins/editable/miniprogram/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,9 @@ module.exports = {
.replace('<video', '<video bindtap="mediaTap"')
.replace('audio ', 'audio bindtap="mediaTap" ')
} else if (file.path.includes('node.js') && file.extname === '.js') {
content = `function getTop(e) {
content = `
const Parser = require('../parser')
function getTop(e) {
let top
// #ifndef MP-ALIPAY
top = e.detail.y
Expand Down Expand Up @@ -622,6 +624,7 @@ module.exports = {
const node = this.getNode(i)
const items = this.root._getItem(node)
this.root._edit = this
const parser = new Parser(this.root)
this.i = i
this.root._maskTap()
this.setData({
Expand All @@ -639,7 +642,7 @@ module.exports = {
if (items[tapIndex] === '换图') {
// 换图
this.root.getSrc('img', node.attrs.src || '').then(url => {
this.root._editVal('nodes[' + (this.properties.opts[7] + i).replace(/_/g, '].children[') + '].attrs.src', node.attrs.src, url instanceof Array ? url[0] : url, true)
this.root._editVal('nodes[' + (this.properties.opts[7] + i).replace(/_/g, '].children[') + '].attrs.src', node.attrs.src, parser.getUrl(url instanceof Array ? url[0] : url), true)
}).catch(() => { })
} else if (items[tapIndex] === '宽度') {
// 更改宽度
Expand Down Expand Up @@ -675,12 +678,12 @@ module.exports = {
this.root.getSrc('link', node.a ? node.a.href : '').then(url => {
// 如果有 a 标签则替换 href
if (node.a) {
this.root._editVal('nodes[' + (this.properties.opts[7] + i).replace(/_/g, '].children[') + '].a.href', node.a.href, url, true)
this.root._editVal('nodes[' + (this.properties.opts[7] + i).replace(/_/g, '].children[') + '].a.href', node.a.href, parser.getUrl(url), true)
} else {
const link = {
name: 'a',
attrs: {
href: url
href: parser.getUrl(url)
},
children: [node]
}
Expand All @@ -694,7 +697,7 @@ module.exports = {
} else if (items[tapIndex] === '预览图') {
// 设置预览图链接
this.root.getSrc('img', node.attrs['original-src'] || '').then(url => {
this.root._editVal('nodes[' + (this.properties.opts[7] + i).replace(/_/g, '].children[') + '].attrs.original-src', node.attrs['original-src'], url instanceof Array ? url[0] : url, true)
this.root._editVal('nodes[' + (this.properties.opts[7] + i).replace(/_/g, '].children[') + '].attrs.original-src', node.attrs['original-src'], parser.getUrl(url instanceof Array ? url[0] : url), true)
wx.showToast({
title: '成功'
})
Expand Down
10 changes: 6 additions & 4 deletions plugins/editable/uni-app/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ module.exports = {
.replace('audio ', 'audio @tap="mediaTap" ')
.replace('<script>',
`<script>
import Parser from '../parser'
function getTop(e) {
let top
// #ifdef H5 || APP-PLUS
Expand Down Expand Up @@ -545,6 +546,7 @@ function getTop(e) {
const i = e.currentTarget.dataset.i
const node = this.childs[i]
const items = this.root._getItem(node)
const parser = new Parser(this.root)
this.root._edit = this
this.i = i
this.root._maskTap()
Expand All @@ -557,7 +559,7 @@ function getTop(e) {
if (items[tapIndex] === '换图') {
// 换图
this.root.getSrc('img', node.attrs.src || '').then(url => {
this.root._editVal(this.opts[7] + '.' + i + '.attrs.src', node.attrs.src, url instanceof Array ? url[0] : url, true)
this.root._editVal(this.opts[7] + '.' + i + '.attrs.src', node.attrs.src, parser.getUrl(url instanceof Array ? url[0] : url), true)
}).catch(() => { })
} else if (items[tapIndex] === '宽度') {
// 更改宽度
Expand Down Expand Up @@ -593,12 +595,12 @@ function getTop(e) {
this.root.getSrc('link', node.a ? node.a.href : '').then(url => {
// 如果有 a 标签则替换 href
if (node.a) {
this.root._editVal(this.opts[7] + '.' + i + '.a.href', node.a.href, url, true)
this.root._editVal(this.opts[7] + '.' + i + '.a.href', node.a.href, parser.getUrl(url), true)
} else {
const link = {
name: 'a',
attrs: {
href: url
href: parser.getUrl(url)
},
children: [node]
}
Expand All @@ -612,7 +614,7 @@ function getTop(e) {
} else if (items[tapIndex] === '预览图') {
// 设置预览图链接
this.root.getSrc('img', node.attrs['original-src'] || '').then(url => {
this.root._editVal(this.opts[7] + '.' + i + '.attrs.original-src', node.attrs['original-src'], url instanceof Array ? url[0] : url, true)
this.root._editVal(this.opts[7] + '.' + i + '.attrs.original-src', node.attrs['original-src'], parser.getUrl(url instanceof Array ? url[0] : url), true)
uni.showToast({
title: '成功'
})
Expand Down

0 comments on commit ca66d5e

Please sign in to comment.