/**
* 按照正则reg把target找出并用replace按照scale(和unit单位)批量替换掉
* @param {Object} reg
* @param {Object} target
* @param {Object} scale
* @param {Object} unit
*/
function replaceAll(reg,target,scale,unit){
var result = target.match(reg);
for(var i in result){
target = target.replace(result[i],parseFloat(result[i])*scale+unit)
}
return target;
}
/**
* htmlTowxml
* @param {Object} inputValue
*/
function htmlTowxml(inputValue) {
inputValue = inputValue.replace(/<div |<p |<table |<tr |<ul |<dl |<h1 |<h2 |<h3 |<h4 |<h5 |<h6 |<nav |<head |<header |<footer |<article |<aside /ig, '<view ')
inputValue = inputValue.replace(/<div>|<p>|<table>|<tr>|<ul>|<dl>|<h1>|<h2>|<h3>|<h4>|<h5>|<h6>|<nav>|<head>|<header>|<footer>|<article>|<aside>/ig, '<view>')
inputValue = inputValue.replace(/<\/div>|<\/p>|<\/table>|<\/tr>|<\/ul>|<\/dl>|<\/h1>|<\/h2>|<\/h3>|<\/h4>|<\/h6>|<\/h6>|<\/nav>|<\/head>|<\/header>|<\/footer>|<\/article>|<\/aside>/ig, '</view>')
inputValue = inputValue.replace(/textarea/ig, 'rich-text')
inputValue = inputValue.replace(/<th |<td |<li |<dt /ig, '<view ')
inputValue = inputValue.replace(/<th>|<td>|<li>|<dt>/ig, '<view>')
inputValue = inputValue.replace(/<\/th>|<\/td>|<\/li>|<\/dt>/ig, '</view>')
inputValue = inputValue.replace(/<span /ig, '<text ')
inputValue = inputValue.replace(/<span>/ig, '<text>')
inputValue = inputValue.replace(/<\/span>/ig, '</text>')
inputValue = inputValue.replace(/<img /ig, '<image ')
inputValue = inputValue.replace(/<img>/ig, '<image>')
inputValue = inputValue.replace(/<\/img>/ig, '</image>')
inputValue = inputValue.replace(/<a /ig, '<navigator ')
inputValue = inputValue.replace(/<a>/ig, '<navigator>')
inputValue = inputValue.replace(/<\/a>/ig, '</navigator>')
inputValue = inputValue.replace(/onclick/ig, 'bindtap')
//vue转wx
// inputValue = inputValue.replace(/@click/ig, 'bindtab')
// inputValue = inputValue.replace(/v-for/ig, 'wx:for')
// inputValue = inputValue.replace(/v-if/ig, 'wx:if')
// inputValue = inputValue.replace(/v-else/ig, 'wx:else')
// 标签里面含有样式rpx
var reg1=/-?\d+(\.\d+)?px/ig;
var reg2=/-?\d+px/ig;
var reg3=/-?\d+(\.\d+)?rem/ig;
var reg4=/-?\d+rem/ig;
inputValue=replaceAll(reg1,inputValue,2,"rpx")
inputValue=replaceAll(reg2,inputValue,2,"rpx")
inputValue=replaceAll(reg3,inputValue,100,"rpx")
inputValue=replaceAll(reg4,inputValue,100,"rpx")
return inputValue;
}
/**
* htmlTouni
* @param {Object} inputValue
*/
function htmlTouni(inputValue) {
inputValue = inputValue.replace(/<div |<p |<table |<tr |<ul |<dl |<h1 |<h2 |<h3 |<h4 |<h5 |<h6 |<nav |<head |<header |<footer |<article |<aside /ig, '<view ')
inputValue = inputValue.replace(/<div>|<p>|<table>|<tr>|<ul>|<dl>|<h1>|<h2>|<h3>|<h4>|<h5>|<h6>|<nav>|<head>|<header>|<footer>|<article>|<aside>/ig, '<view>')
inputValue = inputValue.replace(/<\/div>|<\/p>|<\/table>|<\/tr>|<\/ul>|<\/dl>|<\/h1>|<\/h2>|<\/h3>|<\/h4>|<\/h6>|<\/h6>|<\/nav>|<\/head>|<\/header>|<\/footer>|<\/article>|<\/aside>/ig, '</view>')
inputValue = inputValue.replace(/textarea/ig, 'rich-text')
inputValue = inputValue.replace(/<span |<th |<td |<li |<dt /ig, '<text ')
inputValue = inputValue.replace(/<span>|<th>|<td>|<li>|<dt>/ig, '<text>')
inputValue = inputValue.replace(/<\/span>|<\/th>|<\/td>|<\/li>|<\/dt>/ig, '</text>')
inputValue = inputValue.replace(/<img /ig, '<image ')
inputValue = inputValue.replace(/<img>/ig, '<image>')
inputValue = inputValue.replace(/<\/img>/ig, '</image>')
inputValue = inputValue.replace(/<a /ig, '<navigator ')
inputValue = inputValue.replace(/<a>/ig, '<navigator>')
inputValue = inputValue.replace(/<\/a>/ig, '</navigator>')
inputValue = inputValue.replace(/onclick/ig, '@tap')
//vue转wx
// inputValue = inputValue.replace(/@click/ig, 'bindtab')
// inputValue = inputValue.replace(/v-for/ig, 'wx:for')
// inputValue = inputValue.replace(/v-if/ig, 'wx:if')
// inputValue = inputValue.replace(/v-else/ig, 'wx:else')
// 标签里面含有样式rpx
var reg1=/-?\d+(\.\d+)?px/ig;
var reg2=/-?\d+px/ig;
var reg3=/-?\d+(\.\d+)?rem/ig;
var reg4=/-?\d+rem/ig;
inputValue=replaceAll(reg1,inputValue,2,"rpx")
inputValue=replaceAll(reg2,inputValue,2,"rpx")
inputValue=replaceAll(reg3,inputValue,100,"rpx")
inputValue=replaceAll(reg4,inputValue,100,"rpx")
return inputValue;
}
/**
* vueTowxml
* @param {Object} inputValue
*/
function vueTowxml(inputValue) {
inputValue = inputValue.replace(/<div |<p |<table |<tr |<ul |<dl |<h1 |<h2 |<h3 |<h4 |<h5 |<h6 |<nav |<head |<header |<footer |<article |<aside /ig, '<view ')
inputValue = inputValue.replace(/<div>|<p>|<table>|<tr>|<ul>|<dl>|<h1>|<h2>|<h3>|<h4>|<h5>|<h6>|<nav>|<head>|<header>|<footer>|<article>|<aside>/ig, '<view>')
inputValue = inputValue.replace(/<\/div>|<\/p>|<\/table>|<\/tr>|<\/ul>|<\/dl>|<\/h1>|<\/h2>|<\/h3>|<\/h4>|<\/h6>|<\/h6>|<\/nav>|<\/head>|<\/header>|<\/footer>|<\/article>|<\/aside>/ig, '</view>')
inputValue = inputValue.replace(/textarea/ig, 'rich-text')
inputValue = inputValue.replace(/<span |<th |<td |<li |<dt /ig, '<text ')
inputValue = inputValue.replace(/<span>|<th>|<td>|<li>|<dt>/ig, '<text>')
inputValue = inputValue.replace(/<\/span>|<\/th>|<\/td>|<\/li>|<\/dt>/ig, '</text>')
inputValue = inputValue.replace(/<img /ig, '<image ')
inputValue = inputValue.replace(/<img>/ig, '<image>')
inputValue = inputValue.replace(/<\/img>/ig, '</image>')
inputValue = inputValue.replace(/<a /ig, '<navigator ')
inputValue = inputValue.replace(/<a>/ig, '<navigator>')
inputValue = inputValue.replace(/<\/a>/ig, '</navigator>')
inputValue = inputValue.replace(/onclick/ig, 'bindsubmit')
//vue转wx
inputValue = inputValue.replace(/@click/ig, 'bindtab')
inputValue = inputValue.replace(/@input/ig, 'bindinput')
inputValue = inputValue.replace(/v-for/ig, 'wx:for')
inputValue = inputValue.replace(/v-if/ig, 'wx:if')
inputValue = inputValue.replace(/v-else/ig, 'wx:else')
// 标签里面含有样式rpx
var reg1=/-?\d+(\.\d+)?px/ig;
var reg2=/-?\d+px/ig;
var reg3=/-?\d+(\.\d+)?rem/ig;
var reg4=/-?\d+rem/ig;
inputValue=replaceAll(reg1,inputValue,2,"rpx")
inputValue=replaceAll(reg2,inputValue,2,"rpx")
inputValue=replaceAll(reg3,inputValue,100,"rpx")
inputValue=replaceAll(reg4,inputValue,100,"rpx")
return inputValue;
}
/**
* vueTouni
* @param {Object} inputValue
*/
function vueTouni(inputValue) {
inputValue = inputValue.replace(/<div |<p |<table |<tr |<ul |<dl |<h1 |<h2 |<h3 |<h4 |<h5 |<h6 |<nav |<head |<header |<footer |<article |<aside /ig, '<view ')
inputValue = inputValue.replace(/<div>|<p>|<table>|<tr>|<ul>|<dl>|<h1>|<h2>|<h3>|<h4>|<h5>|<h6>|<nav>|<head>|<header>|<footer>|<article>|<aside>/ig, '<view>')
inputValue = inputValue.replace(/<\/div>|<\/p>|<\/table>|<\/tr>|<\/ul>|<\/dl>|<\/h1>|<\/h2>|<\/h3>|<\/h4>|<\/h6>|<\/h6>|<\/nav>|<\/head>|<\/header>|<\/footer>|<\/article>|<\/aside>/ig, '</view>')
inputValue = inputValue.replace(/textarea/ig, 'rich-text')
inputValue = inputValue.replace(/<span |<th |<td |<li |<dt /ig, '<text ')
inputValue = inputValue.replace(/<span>|<th>|<td>|<li>|<dt>/ig, '<text>')
inputValue = inputValue.replace(/<\/span>|<\/th>|<\/td>|<\/li>|<\/dt>/ig, '</text>')
inputValue = inputValue.replace(/<img /ig, '<image ')
inputValue = inputValue.replace(/<img>/ig, '<image>')
inputValue = inputValue.replace(/<\/img>/ig, '</image>')
inputValue = inputValue.replace(/<a /ig, '<navigator ')
inputValue = inputValue.replace(/<a>/ig, '<navigator>')
inputValue = inputValue.replace(/<\/a>/ig, '</navigator>')
inputValue = inputValue.replace(/onclick/ig, 'bindsubmit')
// 标签里面含有样式rpx
var reg1=/-?\d+(\.\d+)?px/ig;
var reg2=/-?\d+px/ig;
var reg3=/-?\d+(\.\d+)?rem/ig;
var reg4=/-?\d+rem/ig;
inputValue=replaceAll(reg1,inputValue,2,"rpx")
inputValue=replaceAll(reg2,inputValue,2,"rpx")
inputValue=replaceAll(reg3,inputValue,100,"rpx")
inputValue=replaceAll(reg4,inputValue,100,"rpx")
return inputValue;
}
/**
* vueTothinkphp
* @param {Object} inputValue
*/
function vueTothinkphp(inputValue) {
inputValue = inputValue.replace(/{{/ig, '{$')
inputValue = inputValue.replace(/}}/ig, '}')
return inputValue;
}
/**
* wxmlTohtml
* @param {Object} inputValue
*/
function wxmlTohtml(inputValue) {
if(APP_CONFIG.dom_type==2){
}else{
inputValue = inputValue.replace(/<view |<scroll-view |<cover-view |<swiper |<swiper-item |<checkbox-group |<radio-group /ig, '<div ')
inputValue = inputValue.replace(/<view>|<scroll-view>|<cover-view>|<swiper>|<swiper-item>|<checkbox-group>|<radio-group>/ig, '<div>')
inputValue = inputValue.replace(/<\/view>|<\/scroll-view>|<\/cover-view>|<\/swiper>|<\/swiper-item>|<\/checkbox-group>|<\/radio-group>/ig, '</div>')
inputValue = inputValue.replace(/<text /ig, '<span ')
inputValue = inputValue.replace(/<text>/ig, '<span>')
inputValue = inputValue.replace(/<\/text>/ig, '</span>')
inputValue = inputValue.replace(/<checkbox /ig, '<input type="checkbox" ')
inputValue = inputValue.replace(/<checkbox>/ig, '<input type="checkbox"> ')
inputValue = inputValue.replace(/<\/checkbox>/ig, '')
inputValue = inputValue.replace(/<radio /ig, '<input type="radio" ')
inputValue = inputValue.replace(/<radio>/ig, '<input type="radio"> ')
inputValue = inputValue.replace(/<\/radio>/ig, '')
inputValue = inputValue.replace(/<image |<cover-image /ig, '<img ')
inputValue = inputValue.replace(/<image>|<cover-image>/ig, '<img>')
inputValue = inputValue.replace(/<\/image>|<\/cover-image>/ig, '')
inputValue = inputValue.replace(/bindsubmit/ig, 'onclick')
inputValue = inputValue.replace(/bindtap/ig, 'onclick')
inputValue = inputValue.replace(/bindinput/ig, 'oninput')
inputValue = inputValue.replace(/rich-text/ig, 'textarea')
// 标签里面含有样式px
var reg1=/-?\d+(\.\d+)?rpx/ig;
var reg2=/-?\d+rpx/ig;
inputValue=replaceAll(reg1,inputValue,0.5,"px")
inputValue=replaceAll(reg2,inputValue,0.5,"px")
return inputValue;
}
}
/**
* wxmlTovue
* @param {Object} inputValue
*/
function wxmlTovue(inputValue) {
if(APP_CONFIG.dom_type==2){
var x2js = new X2JS();
let _obj=x2js.xml_str2json(inputValue);
console.log(inputValue)
console.log(_obj);
return x2js.json2xml_str(_obj)
}else{
// inputValue = inputValue.replace(/<view |<scroll-view |<cover-view |<swiper |<swiper-item |<checkbox-group |<radio-group /ig, '<div ')
// inputValue = inputValue.replace(/<view>|<scroll-view>|<cover-view>|<swiper>|<swiper-item>|<checkbox-group>|<radio-group>/ig, '<div>')
// inputValue = inputValue.replace(/<\/view>|<\/scroll-view>|<\/cover-view>|<\/swiper>|<\/swiper-item>|<\/checkbox-group>|<\/radio-group>/ig, '</div>')
inputValue = inputValue.replace(/<view |<cover-view |<checkbox-group |<radio-group /ig, '<div ')
inputValue = inputValue.replace(/<view>|<cover-view>|<checkbox-group>|<radio-group>/ig, '<div>')
inputValue = inputValue.replace(/<\/view>|<\/cover-view>|<\/checkbox-group>|<\/radio-group>/ig, '</div>')
inputValue = inputValue.replace(/<text /ig, '<span ')
inputValue = inputValue.replace(/<text>/ig, '<span>')
inputValue = inputValue.replace(/<\/text>/ig, '</span>')
inputValue = inputValue.replace(/<checkbox /ig, '<input type="checkbox" ')
inputValue = inputValue.replace(/<checkbox>/ig, '<input type="checkbox"> ')
inputValue = inputValue.replace(/<\/checkbox>/ig, '')
inputValue = inputValue.replace(/<radio /ig, '<input type="radio" ')
inputValue = inputValue.replace(/<radio>/ig, '<input type="radio"> ')
inputValue = inputValue.replace(/<\/radio>/ig, '')
inputValue = inputValue.replace(/<image |<cover-image /ig, '<img ')
inputValue = inputValue.replace(/<image>|<cover-image>/ig, '<img>')
inputValue = inputValue.replace(/<\/image>|<\/cover-image>/ig, '')
// inputValue = inputValue.replace(/bindsubmit/ig, 'onclick')
inputValue = inputValue.replace(/rich-text/ig, 'textarea')
// inputValue = inputValue.replace(/wx:for/ig, 'v-for')
// inputValue = inputValue.replace(/wx:if/ig, 'v-if')
// inputValue = inputValue.replace(/wx:else/ig, 'v-else')
// inputValue = inputValue.replace(/wx:key/ig, ':key')
if(APP_CONFIG.dom_type==3){
inputValue=jQueryWxmlToVue(inputValue)
// 标签里面含有样式px
var reg1=/-?\d+(\.\d+)?rpx/ig;
var reg2=/-?\d+rpx/ig;
inputValue=replaceAll(reg1,inputValue,0.5,"px")
inputValue=replaceAll(reg2,inputValue,0.5,"px")
inputValue = inputValue.replace(/@tap/g, '@click');
}else {
inputValue=inputValue.replace(/data-(.*?)=\"{{(.*?)}}\"/g, res => {
res=":"+res;
res = res.replace(/\"\{\{/ig, '"')
res = res.replace(/\}\}\"/ig, '"')
res = res.replace(/\'\{\{/ig, "'")
res = res.replace(/\}\}\'/ig, "'")
return res;
});
inputValue=inputValue.replace(/data-(.*?)=\'{{(.*?)}}\'/g, res => {
res=":"+res;
res = res.replace(/\"\{\{/ig, '"')
res = res.replace(/\}\}\"/ig, '"')
res = res.replace(/\'\{\{/ig, "'")
res = res.replace(/\}\}\'/ig, "'")
return res;
});
inputValue = inputValue.replace(/wx\:else/ig, 'v-else')
// 标签里面含有样式px
var reg1=/-?\d+(\.\d+)?rpx/ig;
var reg2=/-?\d+rpx/ig;
inputValue=replaceAll(reg1,inputValue,0.5,"px")
inputValue=replaceAll(reg2,inputValue,0.5,"px")
inputValue=wxmlTouni(inputValue);
inputValue = inputValue.replace(/@tap/g, '@click');
inputValue=toVueTtext(inputValue);
}
return inputValue;
}
}
/**
* wxmlTouni
* @param {Object} inputValue
*/
function wxmlTouni(inputValue) {
if(APP_CONFIG.dom_type==3){
inputValue=jQueryWxmlToUni(inputValue)
}else {
// 事件替换
inputValue = inputValue.replace(/bindtap/g, '@tap')
inputValue = inputValue.replace(/bindinput/g, '@input')
inputValue = inputValue.replace(/bindchange/g, '@change')
inputValue = inputValue.replace(/bindscroll/g, '@scroll')
inputValue = inputValue.replace(/bindscrolltolower/g, '@scrolltolower')
inputValue = inputValue.replace(/bindconfirm/g, '@confirm')
inputValue = inputValue.replace(/bindblur/g, '@blur')
inputValue = inputValue.replace(/bindlongtap/g, '@longtap')
inputValue = inputValue.replace(/catchtouchmove/g, '@touchmove')
// 模板
inputValue = inputValue.replace(/wx\:if/ig, 'v-if')
inputValue = inputValue.replace(/wx\:else/ig, 'v-else')
inputValue = inputValue.replace(/wx\:key/ig, ':key')
inputValue = inputValue.replace(/wx\:for=\"\{\{/g, 'v-for= "(item,index) in ');
inputValue = inputValue.replace(/wx\:for=\'\{\{/g, "v-for= '(item,index) in ");
// 数量值转化
inputValue = inputValue.replace(/ value=\"\{\{/g, ' :value="');
inputValue = inputValue.replace(/ value=\'\{\{/g, " :value='");
inputValue = inputValue.replace(/ src=\"\{\{/g, ' :src="');
inputValue = inputValue.replace(/ src=\'\{\{/g, " :src='");
inputValue = inputValue.replace(/ url=\"\{\{/g, ' :url="');
inputValue = inputValue.replace(/ url=\'\{\{/g, " :url='");
inputValue = inputValue.replace(/ class=\"\{\{/g, ' :class="');
inputValue = inputValue.replace(/ class=\'\{\{/g, " :class='");
inputValue = inputValue.replace(/ style=\"\{\{/g, ' :style="');
inputValue = inputValue.replace(/ style=\'\{\{/g, " :style='");
inputValue=inputValue.replace(/data-(.*?)=\"{{(.*?)}}\"/g, res => {
res=":"+res;
res = res.replace(/\"\{\{/ig, '"')
res = res.replace(/\}\}\"/ig, '"')
res = res.replace(/\'\{\{/ig, "'")
res = res.replace(/\}\}\'/ig, "'")
return res;
});
inputValue=inputValue.replace(/data-(.*?)=\'{{(.*?)}}\'/g, res => {
res=":"+res;
res = res.replace(/\"\{\{/ig, '"')
res = res.replace(/\}\}\"/ig, '"')
res = res.replace(/\'\{\{/ig, "'")
res = res.replace(/\}\}\'/ig, "'")
return res;
});
// 括号模板转化
inputValue = inputValue.replace(/ }}{{ /ig, '+')
inputValue = inputValue.replace(/\"\{\{/ig, '"')
inputValue = inputValue.replace(/\}\}\"/ig, '"')
inputValue = inputValue.replace(/\'\{\{/ig, "'")
inputValue = inputValue.replace(/\}\}\'/ig, "'")
// 标签里面含有样式px
// var reg1=/-?\d+(\.\d+)?rpx/ig;
// var reg2=/-?\d+rpx/ig;
// inputValue=replaceAll(reg1,inputValue,0.5,"px")
// inputValue=replaceAll(reg2,inputValue,0.5,"px")
}
return inputValue;
}
/**
* uniTohtml
* @param {Object} inputValue
*/
function uniTohtml(inputValue) {
inputValue = inputValue.replace(/<view |<scroll-view |<cover-view |<swiper |<swiper-item |<checkbox-group |<radio-group /ig, '<div ')
inputValue = inputValue.replace(/<view>|<scroll-view>|<cover-view>|<swiper>|<swiper-item>|<checkbox-group>|<radio-group>/ig, '<div>')
inputValue = inputValue.replace(/<\/view>|<\/scroll-view>|<\/cover-view>|<\/swiper>|<\/swiper-item>|<\/checkbox-group>|<\/radio-group>/ig, '</div>')
inputValue = inputValue.replace(/<text /ig, '<span ')
inputValue = inputValue.replace(/<text>/ig, '<span>')
inputValue = inputValue.replace(/<\/text>/ig, '</span>')
inputValue = inputValue.replace(/<checkbox /ig, '<input type="checkbox" ')
inputValue = inputValue.replace(/<checkbox>/ig, '<input type="checkbox"> ')
inputValue = inputValue.replace(/<\/checkbox>/ig, '')
inputValue = inputValue.replace(/<radio /ig, '<input type="radio" ')
inputValue = inputValue.replace(/<radio>/ig, '<input type="radio"> ')
inputValue = inputValue.replace(/<\/radio>/ig, '')
inputValue = inputValue.replace(/<image |<cover-image /ig, '<img ')
inputValue = inputValue.replace(/<image>|<cover-image>/ig, '<img>')
inputValue = inputValue.replace(/<\/image>|<\/cover-image>/ig, '')
inputValue = inputValue.replace(/@submit/ig, 'onclick')
inputValue = inputValue.replace(/@tap/ig, 'onclick')
inputValue = inputValue.replace(/@input/ig, 'oninput')
inputValue = inputValue.replace(/@click/ig, 'onclick')
inputValue = inputValue.replace(/rich-text/ig, 'textarea')
// 标签里面含有样式px
// var reg1=/-?\d+(\.\d+)?rpx/ig;
// var reg2=/-?\d+rpx/ig;
// inputValue=replaceAll(reg1,inputValue,0.5,"px")
// inputValue=replaceAll(reg2,inputValue,0.5,"px")
switch (APP_CONFIG.style_company){
case 'rem':
inputValue =rpxTorem(inputValue)
break;
case 'px':
inputValue=rpxTopx(inputValue)
break;
default:
inputValue=rpxTopx(inputValue)
break;
}
return inputValue;
}
/**
* uniTowxml
* @param {Object} inputValue
*/
function uniTowxml(inputValue) {
if(APP_CONFIG.dom_type==3){
inputValue=jQueryUniToWxml(inputValue)
}else {
// 事件替换
inputValue = inputValue.replace(/@tap/g, 'bindtap')
inputValue = inputValue.replace(/@click/g, 'bindtap')
inputValue = inputValue.replace(/@input/g, 'bindinput')
inputValue = inputValue.replace(/@change/g, 'bindchange')
inputValue = inputValue.replace(/@scroll/g, 'bindscroll')
inputValue = inputValue.replace(/@scrolltolower/g, 'bindscrolltolower')
inputValue = inputValue.replace(/@confirm/g, 'bindconfirm')
inputValue = inputValue.replace(/@blur/g, 'bindblur')
inputValue = inputValue.replace(/@longtap/g, 'bindlongtap')
inputValue = inputValue.replace(/@touchmove/g, 'catchtouchmove')
// 模板
inputValue = inputValue.replace(/v-if="(.*?)"/ig, res=>{
res=res.replace(/v-if/ig, 'wx:if')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
})
inputValue = inputValue.replace(/v-if='(.*?)'/ig, res=>{
res=res.replace(/v-if/ig, 'wx:if')
res=res.replace(/'(.*?)'/g,re=>{
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
})
inputValue = inputValue.replace(/v-else/ig, 'wx:else')
inputValue = inputValue.replace(/:key/ig, 'wx:key')
inputValue = inputValue.replace(/v-for="(item,index) in (.*?)"/g, res=>{
res=res.replace(/v-for="(item,index) in /ig, 'wx:for="')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
inputValue = inputValue.replace(/v-for='(item,index) in (.*?)'/g, res=>{
res=res.replace(/v-for='(item,index) in /ig, "wx:for='")
res=res.replace(/'(.*?)'/g,re=>{
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
inputValue = inputValue.replace(/v-for='(.*?)'/g, res=>{
res=res.replace(/v-for/ig, "wx:for")
let a=res.match(/\((.*?)\)/ig)[0];
a=a.replace('(','');
a=a.replace(')','');
let a_array=a.split(',');
res=res.replace(/\((.*?)\) in /g, "")
res=res.replace(/'(.*?)'/g,re=>{
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}'";
if(a_array[0]){
re=re+" wx:for-item='"+a_array[0]+"' "
}
if(a_array[1]){
re=re+" wx:for-index='"+a_array[1]+"'";
}
return re;
})
return res;
});
inputValue = inputValue.replace(/v-for="(.*?)"/g, res=>{
res=res.replace(/v-for/ig, 'wx:for')
console.log(res)
let a=res.match(/\((.*?)\)/ig)[0];
a=a.replace('(','');
a=a.replace(')','');
let a_array=a.split(',');
res=res.replace(/\((.*?)\) in /g, "")
console.log(res)
res=res.replace(/"(.*?)"/g,re=>{
console.log(re)
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}"';
if(a_array[0]){
re=re+' wx:for-item="'+a_array[0]+'" ';
}
if(a_array[1]){
re=re+' wx:for-index="'+a_array[1]+'" ';
}
return re;
})
return res;
});
// 数量值转化
inputValue = inputValue.replace(/ :value="(.*?)" /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
inputValue = inputValue.replace(/ :value='(.*?)' /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/'(.*?)'/g,re=>{
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
inputValue = inputValue.replace(/ :src="(.*?)" /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
inputValue = inputValue.replace(/ :src='(.*?)' /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/'(.*?)'/g,re=>{
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
inputValue = inputValue.replace(/ :url="(.*?)" /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
inputValue = inputValue.replace(/ :url='(.*?)' /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/'(.*?)'/g,re=>{
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
inputValue = inputValue.replace(/ :class="(.*?)" /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
inputValue = inputValue.replace(/ :class='(.*?)' /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/'(.*?)'/g,re=>{
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
inputValue = inputValue.replace(/ :style="(.*?)" /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
inputValue = inputValue.replace(/ :style='(.*?)' /g, res=>{
res=res.replace(/:/g,'')
res=res.replace(/'(.*?)'/g,re=>{
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
inputValue=inputValue.replace(/ :data-(.*?)="(.*?)" /g, res => {
res=res.replace(/:/g,'')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
inputValue=inputValue.replace(/ :data-(.*?)='(.*?)' /g, res => {
res=res.replace(/:/g,'')
res=res.replace(/'(.*?)'/g,re=>{
console.log(re);
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
inputValue=inputValue.replace(/ :(.*?)="(.*?)" /g, res => {
res=res.replace(/:/g,'')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
inputValue=inputValue.replace(/ :(.*?)='(.*?)' /g, res => {
res=res.replace(/:/g,'')
res=res.replace(/'(.*?)'/g,re=>{
console.log(re);
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
}
// 标签里面含有样式px
// var reg1=/-?\d+(\.\d+)?rpx/ig;
// var reg2=/-?\d+rpx/ig;
// inputValue=replaceAll(reg1,inputValue,0.5,"px")
// inputValue=replaceAll(reg2,inputValue,0.5,"px")
return inputValue;
}
/**
* uniTovue
* @param {Object} inputValue
*/
function uniTovue(inputValue) {
inputValue = inputValue.replace(/<view |<scroll-view |<cover-view |<swiper |<swiper-item |<checkbox-group |<radio-group /ig, '<div ')
inputValue = inputValue.replace(/<view>|<scroll-view>|<cover-view>|<swiper>|<swiper-item>|<checkbox-group>|<radio-group>/ig, '<div>')
inputValue = inputValue.replace(/<\/view>|<\/scroll-view>|<\/cover-view>|<\/swiper>|<\/swiper-item>|<\/checkbox-group>|<\/radio-group>/ig, '</div>')
inputValue = inputValue.replace(/<text /ig, '<span ')
inputValue = inputValue.replace(/<text>/ig, '<span>')
inputValue = inputValue.replace(/<\/text>/ig, '</span>')
inputValue = inputValue.replace(/<checkbox /ig, '<input type="checkbox" ')
inputValue = inputValue.replace(/<checkbox>/ig, '<input type="checkbox"> ')
inputValue = inputValue.replace(/<\/checkbox>/ig, '')
inputValue = inputValue.replace(/<radio /ig, '<input type="radio" ')
inputValue = inputValue.replace(/<radio>/ig, '<input type="radio"> ')
inputValue = inputValue.replace(/<\/radio>/ig, '')
inputValue = inputValue.replace(/<image |<cover-image /ig, '<img ')
inputValue = inputValue.replace(/<image>|<cover-image>/ig, '<img>')
inputValue = inputValue.replace(/<\/image>|<\/cover-image>/ig, '')
inputValue = inputValue.replace(/rich-text/ig, 'textarea')
inputValue = inputValue.replace(/bindsubmit/ig, '@submit')
inputValue = inputValue.replace(/@tap/g, '@click')
switch (APP_CONFIG.style_company){
case 'rem':
inputValue =rpxTorem(inputValue)
break;
case 'px':
inputValue=rpxTopx(inputValue)
break;
default:
inputValue=rpxTopx(inputValue)
break;
}
inputValue=toVueTtext(inputValue);
return inputValue;
// 标签里面含有样式px
// var reg1=/-?\d+(\.\d+)?rpx/ig;
// var reg2=/-?\d+rpx/ig;
// inputValue=replaceAll(reg1,inputValue,0.5,"px")
// inputValue=replaceAll(reg2,inputValue,0.5,"px")
return inputValue;
}
/**
* wxssTocss
* @param {Object} inputValue
*/
function wxssTocss(inputValue) {
inputValue=inputValue.replace(/page{/g,'body{')
inputValue=inputValue.replace(/ image /g,' img ')
inputValue=inputValue.replace(/ image\{/g,' img{')
inputValue=inputValue.replace(/ image{/g,' img{')
inputValue=inputValue.replace(/ image\./g,' img.')
inputValue=inputValue.replace(/ text /g,' span ')
inputValue=inputValue.replace(/ text{/g,' span{')
inputValue=inputValue.replace(/ text\./g,' span.')
inputValue=inputValue.replace(/ view{/g,' div{')
inputValue=inputValue.replace(/ view /g,' div ')
inputValue=inputValue.replace(/ view\./g,' div.')
switch (APP_CONFIG.style_company){
case 'rem':
inputValue=rpxTorem(inputValue)
break;
case 'px':
inputValue=rpxTopx(inputValue)
break;
default:
inputValue=rpxTopx(inputValue)
break;
}
return inputValue;
}
/**
* cssTowxss
* @param {Object} inputValue
*/
function cssTowxss(inputValue) {
inputValue=inputValue.replace(/ img /g,' image ')
inputValue=inputValue.replace(/ img\{/g,' image{')
inputValue=inputValue.replace(/ span /g,' text ')
inputValue=rpxTopx(inputValue)
return inputValue;
}
/**
* pxTorem
* @param {Object} inputValue
*/
function pxTorem(inputValue) {
var reg1=/-?\d+(\.\d+)?px/ig;
var reg2=/-?\d+px/ig;
inputValue=replaceAll(reg1,inputValue,0.02,"rem")
inputValue=replaceAll(reg2,inputValue,0.02,"rem")
return inputValue;
}
/**
* pxTopx
* @param {Object} inputValue
*/
function pxTopx(inputValue) {
var reg1=/-?\d+(\.\d+)?rpx/ig;
var reg2=/-?\d+rpx/ig;
var req=APP_CONFIG.req||1
inputValue=replaceAll(reg1,inputValue,req,"px")
inputValue=replaceAll(reg2,inputValue,req,"px")
return inputValue;
}
/**
* rpxTorem
* @param {Object} inputValue
*/
function rpxTorem(inputValue) {
var reg1=/-?\d+(\.\d+)?rpx/ig;
var reg2=/-?\d+rpx/ig;
inputValue=replaceAll(reg1,inputValue,1/100,"rem")
inputValue=replaceAll(reg2,inputValue,1/100,"rem")
return inputValue;
}
/**
* rpxTopx
* @param {Object} inputValue
*/
function rpxTopx(inputValue) {
var reg1=/-?\d+(\.\d+)?rpx/ig;
var reg2=/-?\d+rpx/ig;
inputValue=replaceAll(reg1,inputValue,0.5,"px")
inputValue=replaceAll(reg2,inputValue,0.5,"px")
return inputValue;
}
/**
* remTorpx
* @param {Object} inputValue
*/
function remTorpx(inputValue) {
var reg3=/-?\d+(\.\d+)?rem/ig;
var reg4=/-?\d+rem/ig;
inputValue=replaceAll(reg3,inputValue,100,"rpx")
inputValue=replaceAll(reg4,inputValue,100,"rpx")
return inputValue;
}
function pxTorpx(inputValue) {
var reg1=/-?\d+(\.\d+)?px/ig;
var reg2=/-?\d+px/ig;
inputValue=replaceAll(reg1,inputValue,2,"rpx")
inputValue=replaceAll(reg2,inputValue,2,"rpx")
return inputValue;
}
function wjsToujs(inputValue) {
//替换setData
if(parseInt(APP_CONFIG.is_setData)){
inputValue = inputValue.replace(/that\.setData\(\{([\s\S]*?)\}\)/g, res=>{
res=res.replace(/that\.setData\(\{([\s\S]*?)\}\)/g,re=>{
re=re.replace(/that\.setData\(\{/g,'')
re=re.replace(/\}\)/g,'')
re=re.replace(/(.*?):(.*?)\n/g,r=>{
// r="."+r;
r=r.replace(/(.*?):/gi,ir=>{
let nrt=ir.match(/\s+/g)[0]
ir=ir.replace(/\s+/g,"");
ir=nrt+"that."+ir;
return ir;
});
r=r.replace(":",'=');
r=r.replace(",",';');
return r;
})
return re;jsjuudgfhaksa0akl
})
return res
})
inputValue = inputValue.replace(/this\.setData\(\{([\s\S]*?)\}\)/g, res=>{
res=res.replace(/this\.setData\(\{([\s\S]*?)\}\)/g,re=>{
re=re.replace(/this\.setData\(\{/g,'')
re=re.replace(/\}\)/g,'')
re=re.replace(/(.*?):(.*?)\n/g,r=>{
// r="this."+r;
r=r.replace(/(.*?):/gi,ir=>{
let nrt=ir.match(/\s+/g)[0]
ir=ir.replace(/\s+/g,"");
ir=nrt+"this."+ir;
return ir;
});
r=r.replace(":",'=');
r=r.replace(",",';');
return r;
})
return re;
})
return res
})
inputValue = inputValue.replace(/\w+([-+.]\w+)*\.setData\(\{([\s\S]*?)\}\)/g, res=>{
res=res.replace(/\w+([-+.]\w+)*\.setData\(\{([\s\S]*?)\}\)/g,re=>{
let that='';
re=re.replace(/\w+([-+.]\w+)*\.setData\(\{/g,to=>{
to.replace(/\w+([-+.]\w+)*\./g,to1=>{
to1.replace(/\w+([-+.]\w+)*/g,to2=>{
that=to2;
})
});
return '';
})
re=re.replace(/\}\)/g,'')
re=re.replace(/(.*?):(.*?)\n/g,r=>{
// r="this."+r;
r=r.replace(/(.*?):/gi,ir=>{
let nrt=ir.match(/\s+/g)[0]
ir=ir.replace(/\s+/g,"");
ir=nrt+that+"."+ir;
return ir;
});
r=r.replace(":",'=');
r=r.replace(",",';');
return r;
})
return re;
})
return res
});
//替换.data.
inputValue = inputValue.replace(/this\.data\./ig, res=>{
res=res.replace(/\.data\./g,'.');
return res;
});
inputValue = inputValue.replace(/that\.data\./ig, res=>{
res=res.replace(/\.data\./g,'.');
return res;
});
}
inputValue = inputValue.replace(/wx\./ig, 'uni.');
// 特殊替换
inputValue = inputValue.replace(/app\.common/g, 'app.globalData.$common');
inputValue = inputValue.replace(/app\.web_server/g, 'app.globalData.$config.web_server');
inputValue = inputValue.replace(/app\.api_server/g, 'app.globalData.$config.api_server');
return inputValue;
}
function ujsTowjs(inputValue) {
inputValue = inputValue.replace(/uni\./ig, 'wx.')
return inputValue;
}
function uniTothinkphp(inputValue) {
inputValue=uniTohtml(inputValue);
// inputValue = inputValue.replace(/<(.*?)v-if=(.*?)></(.*?)>/ig, 'wx.')
$(inputValue).find('[v-if]').map((index,res)=>{
console.log(res);
let att=$(res).attr('v-if')
atts=`<if `+att+`>\n`+res+`</if>`;
return res;
})
inputValue=inputValue.replace(/{{(.*?)}}/g,res=>{
res=res.replace(/{{/g,'{$')
res=res.replace(/}}/g,'}')
return res;
})
return inputValue;
}
function wxmlTothinkphp(inputValue) {
inputValue=wxmlTohtml(inputValue);
return inputValue;
}
function thinkphpTowxml(inputValue) {
inputValue=htmlTowxml(inputValue);
return inputValue;
}
function thinkphpTouni(inputValue) {
inputValue=htmlTouni(inputValue);
return inputValue;
}
//转化为v-text,免中间暴露{{$a}}
function toVueTtext(inputValue) {
if(APP_CONFIG.vue_text==1){
inputValue=jQueryVue(inputValue);
}
return inputValue;
}
//以JQ建立dom树来进行页面渲染修改调整
function jQueryVue(dom,a=0) {
// console.log(dom);
if(!dom) return false;
dom=$(dom);
if(dom.length>1){
$.each(dom,(i,el)=>{
jQueryVue(el);
})
}
if(dom.children().length>0){
let children_s=dom.children();
$.each(children_s,(i,el)=>{
jQueryVue(el);
})
}
if(dom.prop('firstChild')&&dom.prop('firstChild').nodeValue){
console.log(dom.prop('firstChild').nodeValue);
let text=dom.prop('firstChild')&&dom.prop('firstChild').nodeValue;
if(text.includes("{{")||text.includes("}}")){
text=text.replace(/{{/g,'`+');
text=text.replace(/}}/g,'+`');
dom.attr('v-text',"`"+text+"`");
dom.prop('firstChild').nodeValue=""
}
}
// console.log(dom);
return dom.prop("outerHTML");
}
function jQueryWxmlToVue(dom) {
// console.log(dom);
if(!dom) return false;
dom=$(dom);
if(dom.length>1){
$.each(dom,(i,el)=>{
jQueryWxmlToVue(el);
})
}
if(dom.children().length>0){
let children_s=dom.children();
$.each(children_s,(i,el)=>{
jQueryWxmlToVue(el);
})
}else {
console.log(dom);
//value
if(dom.attr('value')){
let value=dom.attr('value');
if(value.includes("{{")&&value.includes("}}")){
value=value.replace(/{{/g,'`+');
value=value.replace(/}}/g,'+`');
dom.attr(':value',"`"+value+"`");
dom.removeAttr('value');
}
}
//src
if(dom.attr('src')){
console.log(dom.tagName);
let src=dom.attr('src');
console.log(src);
if(src.includes("{{")&&src.includes("}}")){
src=src.replace(/{{/g,'`+');
src=src.replace(/}}/g,'+`');
dom.attr(':src',"`"+src+"`");
dom.removeAttr('src');
}
}
}
if(dom.attr('value')){
let value=dom.attr('value');
if(value.includes("{{")&&value.includes("}}")){
value=value.replace(/{{/g,'`+');
value=value.replace(/}}/g,'+`');
dom.attr(':value',"`"+value+"`");
dom.removeAttr('value');
}
}
//src
if(dom.attr('src')){
console.log(dom.tagName);
let src=dom.attr('src');
console.log(src);
if(src.includes("{{")&&src.includes("}}")){
src=src.replace(/{{/g,'`+');
src=src.replace(/}}/g,'+`');
dom.attr(':src',"`"+src+"`");
dom.removeAttr('src');
}
}
if(dom.attr('wx:if')){
let wxif=dom.attr('wx:if');
wxif=wxif.replace(/{{/g,'');
wxif=wxif.replace(/}}/g,'');
dom.attr('v-if',wxif);
dom.removeAttr('wx:if');
}
if(dom.attr('wx:elif')){
let wxif=dom.attr('wx:elif');
wxif=wxif.replace(/{{/g,'');
wxif=wxif.replace(/}}/g,'');
dom.attr('v-else-if',wxif);
dom.removeAttr('wx:elif');
}
//wx:else
if(dom.attr('wx:else')!=undefined){
dom.attr('v-else',"");
dom.removeAttr('wx:else');
}
//wx:for
if(dom.attr('wx:for')){
let wxfor=dom.attr('wx:for');
let wxforitem="";
let wxforindex="";
wxfor=wxfor.replace(/{{/g,'');
wxfor=wxfor.replace(/}}/g,'');
if(dom.attr('wx:for-item')){
wxforitem=dom.attr('wx:for-item');
dom.removeAttr('wx:for-item');
}else {
wxforitem="item";
}
if(dom.attr('wx:for-index')){
wxforindex=dom.attr('wx:for-index');
dom.removeAttr('wx:for-index');
}else {
wxforindex="index";
}
dom.attr('v-for',`(${wxforitem},${wxforindex}) in ${wxfor}`);
dom.removeAttr('wx:for');
}
//wx:key
if(dom.attr('wx:key')){
let wxkey=dom.attr('wx:key');
dom.attr(':key',wxkey);
dom.removeAttr('wx:key');
}
//wx:show
if(dom.attr('wx:show')){
let wxshow=dom.attr('wx:show');
wxshow=wxshow.replace(/{{/g,'');
wxshow=wxshow.replace(/}}/g,'');
dom.attr('v-show',wxshow);
dom.removeAttr('wx:show');
}
//class
if(dom.attr('class')){
let clas=dom.attr('class');
if(clas.includes("{{")&&clas.includes("}}")){
clas=clas.replace(/{{/g,'`+');
clas=clas.replace(/}}/g,'+`');
dom.attr(':class',"`"+clas+"`");
dom.removeAttr('class');
}
}
//style
if(dom.attr('style')){
let style=dom.attr('style');
if(style.includes("{{")&&style.includes("}}")){
style=style.replace(/{{/g,'`+');
style=style.replace(/}}/g,'+`');
dom.attr(':style',"`"+style+"`");
dom.removeAttr('style');
}
}
if(dom.prop('firstChild')&&dom.prop('firstChild').nodeValue){
let text=dom.prop('firstChild')&&dom.prop('firstChild').nodeValue;
if(text.includes("{{")||text.includes("}}")){
text=text.replace(/{{/g,'`+');
text=text.replace(/}}/g,'+`');
dom.attr('v-text',"`"+text+"`");
dom.prop('firstChild').nodeValue=""
}
}
$.each(dom[0].attributes,function(i,el){
console.log(this.name,this.value);
if(this.value.includes("{{")&&this.value.includes("}}")){
let nm=this.name;
let val=this.value;
this.name=`:${nm}`;
val=val.replace(/{{/g,'');
val=val.replace(/}}/g,'');
this.value='`'+val+'`';
dom.attr(":"+this.name,val);
dom.removeAttr(this.name);
}
})
let HTML=dom.prop("outerHTML");
HTML=HTML.replace(/data-(.*?)=\"{{(.*?)}}\"/g, res => {
res=":"+res;
res = res.replace(/\"\{\{/ig, '"')
res = res.replace(/\}\}\"/ig, '"');
res = res.replace(/\'\{\{/ig, "'");
res = res.replace(/\}\}\'/ig, "'");
return res;
});
HTML=HTML.replace(/data-(.*?)=\'{{(.*?)}}\'/g, res => {
res=":"+res;
res = res.replace(/\"\{\{/ig, '"')
res = res.replace(/\}\}\"/ig, '"');
res = res.replace(/\'\{\{/ig, "'");
res = res.replace(/\}\}\'/ig, "'");
return res;
});
HTML = HTML.replace(/v-else=""/g, 'v-else ')
HTML = HTML.replace(/bindtap/g, '@tap')
HTML = HTML.replace(/bindinput/g, '@input')
HTML = HTML.replace(/bindchange/g, '@change')
HTML = HTML.replace(/bindscroll/g, '@scroll')
HTML = HTML.replace(/bindscrolltolower/g, '@scrolltolower')
HTML = HTML.replace(/bindconfirm/g, '@confirm')
HTML = HTML.replace(/bindblur/g, '@blur')
HTML = HTML.replace(/bindlongtap/g, '@longtap')
HTML = HTML.replace(/catchtouchmove/g, '@touchmove')
HTML = HTML.replace(/catchtap/g, '@click.stop')
HTML = HTML.replace(/<block /ig, '<template ')
HTML = HTML.replace(/<block>/ig, '<template>')
HTML = HTML.replace(/<\/block>/ig, '</template>')
return HTML;
}
function jQueryWxmlToUni(dom) {
// console.log(dom);
if(!dom) return false;
dom=$(dom);
if(dom.length>1){
$.each(dom,(i,el)=>{
jQueryWxmlToUni(el);
})
}
if(dom.children().length>0){
let children_s=dom.children();
$.each(children_s,(i,el)=>{
jQueryWxmlToUni(el);
})
}else {
//value
if(dom.attr('value')){
let value=dom.attr('value');
if(value.includes("{{")&&value.includes("}}")){
value=value.replace(/{{/g,'`+');
value=value.replace(/}}/g,'+`');
dom.attr(':value',"`"+value+"`");
dom.removeAttr('value');
}
}
//src
console.log(dom.tagName);
if(dom.attr('src')){
let src=dom.attr('src');
console.log(src);
if(src.includes("{{")&&src.includes("}}")){
src=src.replace(/{{/g,'`+');
src=src.replace(/}}/g,'+`');
dom.attr(':src',"`"+src+"`");
dom.removeAttr('src');
}
}
}
if(dom.attr('value')){
let value=dom.attr('value');
if(value.includes("{{")&&value.includes("}}")){
value=value.replace(/{{/g,'`+');
value=value.replace(/}}/g,'+`');
dom.attr(':value',"`"+value+"`");
dom.removeAttr('value');
}
}
//src
console.log(dom.tagName);
if(dom.attr('src')){
let src=dom.attr('src');
console.log(src);
if(src.includes("{{")&&src.includes("}}")){
src=src.replace(/{{/g,'`+');
src=src.replace(/}}/g,'+`');
dom.attr(':src',"`"+src+"`");
dom.removeAttr('src');
}
}
if(dom.prop('firstChild')){
//wx:if
if(dom.attr('wx:if')){
let wxif=dom.attr('wx:if');
wxif=wxif.replace(/{{/g,'`+');
wxif=wxif.replace(/}}/g,'+`');
dom.attr('v-if',"`"+wxif+"`");
dom.removeAttr('wx:if');
}
//wx:else
if(dom.attr('wx:else')){
dom.attr('v-else',"");
dom.removeAttr('wx:else');
}
//wx:for
if(dom.attr('wx:for')){
let wxfor=dom.attr('wx:for');
let wxforitem="";
let wxforindex="";
wxfor=wxfor.replace(/{{/g,'');
wxfor=wxfor.replace(/}}/g,'');
if(dom.attr('wx:for-item')){
wxforitem=dom.attr('wx:for-item');
dom.removeAttr('wx:for-item');
}else {
wxforitem="item";
}
if(dom.attr('wx:for-index')){
wxforindex=dom.attr('wx:for-index');
dom.removeAttr('wx:for-index');
}else {
wxforindex="index";
}
dom.attr('v-for',`(${wxforitem},${wxforindex}) in ${wxfor}`);
dom.removeAttr('wx:for');
}
//wx:key
if(dom.attr('wx:key')){
let wxkey=dom.attr('wx:key');
dom.attr(':key',wxkey);
dom.removeAttr('wx:key');
}
//wx:show
if(dom.attr('wx:show')){
let wxshow=dom.attr('wx:show');
wxshow=wxshow.replace(/{{/g,'');
wxshow=wxshow.replace(/}}/g,'');
dom.attr('v-show',wxshow);
dom.removeAttr('wx:show');
}
//class
if(dom.attr('class')){
let clas=dom.attr('class');
if(clas.includes("{{")&&clas.includes("}}")){
clas=clas.replace(/{{/g,'`+');
clas=clas.replace(/}}/g,'+`');
dom.attr(':class',"`"+clas+"`");
dom.removeAttr('class');
}
}
//style
if(dom.attr('style')){
let style=dom.attr('style');
if(style.includes("{{")&&style.includes("}}")){
style=style.replace(/{{/g,'`+');
style=style.replace(/}}/g,'+`');
dom.attr(':style',"`"+style+"`");
dom.removeAttr('style');
}
}
}
if(dom.prop('firstChild')&&dom.prop('firstChild').nodeValue){
let text=dom.prop('firstChild')&&dom.prop('firstChild').nodeValue;
if(text.includes("{{")||text.includes("}}")){
text=text.replace(/{{/g,'`+');
text=text.replace(/}}/g,'+`');
dom.attr('v-text',"`"+text+"`");
dom.prop('firstChild').nodeValue=""
}
}
let HTML=dom.prop("outerHTML");
HTML=HTML.replace(/data-(.*?)=\"{{(.*?)}}\"/g, res => {
res=":"+res;
res = res.replace(/\"\{\{/ig, '"')
res = res.replace(/\}\}\"/ig, '"');
res = res.replace(/\'\{\{/ig, "'");
res = res.replace(/\}\}\'/ig, "'");
return res;
});
HTML=HTML.replace(/data-(.*?)=\'{{(.*?)}}\'/g, res => {
res=":"+res;
res = res.replace(/\"\{\{/ig, '"')
res = res.replace(/\}\}\"/ig, '"');
res = res.replace(/\'\{\{/ig, "'");
res = res.replace(/\}\}\'/ig, "'");
return res;
});
HTML = HTML.replace(/bindtap/g, '@tap')
HTML = HTML.replace(/bindinput/g, '@input')
HTML = HTML.replace(/bindchange/g, '@change')
HTML = HTML.replace(/bindscroll/g, '@scroll')
HTML = HTML.replace(/bindscrolltolower/g, '@scrolltolower')
HTML = HTML.replace(/bindconfirm/g, '@confirm')
HTML = HTML.replace(/bindblur/g, '@blur')
HTML = HTML.replace(/bindlongtap/g, '@longtap')
HTML = HTML.replace(/catchtouchmove/g, '@touchmove')
return HTML;
}
function jQueryUniToWxml(dom) {
// console.log(dom);
if(!dom) return false;
dom=$(dom);
if(dom.length>1){
$.each(dom,(i,el)=>{
jQueryUniToWxml(el);
})
}
if(dom.children().length>0){
let children_s=dom.children();
$.each(children_s,(i,el)=>{
jQueryUniToWxml(el);
})
}else {
//value
if(dom.attr(':value')){
let value=dom.attr(':value');
dom.attr('value',"{{"+value+"}}");
dom.removeAttr(':value');
}
//src
if(dom.attr(':src')){
let src=dom.attr(':src');
dom.attr('src',"{{"+src+"}}");
dom.removeAttr(':src');
}
}
//value
if(dom.attr(':value')){
let value=dom.attr(':value');
dom.attr('value',"{{"+value+"}}");
dom.removeAttr(':value');
}
//src
if(dom.attr(':src')){
let src=dom.attr(':src');
dom.attr('src',"{{"+src+"}}");
dom.removeAttr(':src');
}
if(dom.prop('firstChild')){
//wx:if
if(dom.attr('v-if')){
let wxif=dom.attr('v-if');
dom.attr('wx:if',"{{"+wxif+"}}");
dom.removeAttr('v-if');
}
//wx:else
if(dom.attr('v-else')){
dom.attr('wx:else',"");
dom.removeAttr('v-else');
}
//wx:for
if(dom.attr('v-for')){
let wxfor=dom.attr('v-for');
let wxforitem="";
let wxforindex="";
let wxfor_arr=wxfor.split(" in ");
wxfor=wxfor_arr[1];
let wxfor_arr_arr= wxfor_arr[0].replace(/\(|\)/g,'').split(",")
wxforitem=wxfor_arr_arr[0];
wxforindex=wxfor_arr_arr[1];
dom.attr('wx:for',"{{"+wxfor+"}}");
dom.attr('wx:for-item',wxforitem);
dom.attr('wx:for-index',wxforindex);
dom.removeAttr('v-for');
}
//wx:key
if(dom.attr(':key')){
let wxkey=dom.attr(':key');
dom.attr('wx:key',wxkey);
dom.removeAttr(':key');
}
//wx:show
if(dom.attr('v-show')){
let wxshow=dom.attr('v-show');
dom.attr('wx:show',"{{"+wxshow+"}}");
dom.removeAttr('v-show');
}
//class
if(dom.attr(':class')){
let clas=dom.attr(':class');
dom.attr('class',dom.attr('class')+" {{"+clas+"}}");
dom.removeAttr(':class');
}
//style
if(dom.attr(':style')){
let style=dom.attr(':style');
dom.attr('style',dom.attr('style')+" {{"+style+"}}");
dom.removeAttr(':style');
}
if(dom.attr('v-text')){
dom.prop('firstChild').nodeValue="{{"+dom.attr('v-text')+"}}";
dom.removeAttr('v-text');
}
}
let HTML=dom.prop("outerHTML");
HTML = HTML.replace(/@tap/g, 'bindtap')
HTML = HTML.replace(/@click/g, 'bindtap')
HTML = HTML.replace(/@input/g, 'bindinput')
HTML = HTML.replace(/@change/g, 'bindchange')
HTML = HTML.replace(/@scroll/g, 'bindscroll')
HTML = HTML.replace(/@scrolltolower/g, 'bindscrolltolower')
HTML = HTML.replace(/@confirm/g, 'bindconfirm')
HTML = HTML.replace(/@blur/g, 'bindblur')
HTML = HTML.replace(/@longtap/g, 'bindlongtap')
HTML = HTML.replace(/@touchmove/g, 'catchtouchmove')
HTML=HTML.replace(/ :data-(.*?)="(.*?)" /g, res => {
res=res.replace(/:/g,'')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
HTML=HTML.replace(/ :data-(.*?)='(.*?)' /g, res => {
res=res.replace(/:/g,'')
res=res.replace(/'(.*?)'/g,re=>{
console.log(re);
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
HTML=HTML.replace(/ :(.*?)="(.*?)" /g, res => {
res=res.replace(/:/g,'')
res=res.replace(/"(.*?)"/g,re=>{
re=re.replace('"','')
re=re.replace('"','')
re='"{{'+re+'}}" ';
return re;
})
return res;
});
HTML=HTML.replace(/ :(.*?)='(.*?)' /g, res => {
res=res.replace(/:/g,'')
res=res.replace(/'(.*?)'/g,re=>{
console.log(re);
re=re.replace("'",'')
re=re.replace("'",'')
re="'{{"+re+"}}' ";
return re;
})
return res;
});
return HTML;
}
/*---------------------------独立组------------------------------*/
function is_NaN() {
var inputValue=$("#toData").val();
let naNCount=NaNCount(inputValue);
if(naNCount>0){
$("#err_num").html("报错统计:"+naNCount);
inputValue=inputValue.replace(/NaN/g,res=>{
res="=======【"+res+"】=======";
return res;
})
$("#toData").html(inputValue);
}else {
$("#err_num").html("");
}
}
//js统计字符串中包含的特定字符个数
function NaNCount(strSource) {
//统计字符串中包含{}或{xxXX}的个数
var thisCount = 0;
strSource.replace(/NaN/g, function (m, i) {
//m为找到的{xx}元素、i为索引
thisCount++;
return m;
});
return thisCount;
}
function settingBtn() {
let setting_obj = $("#setting_from").serializeArray();
setting_obj.map(re=>{
APP_CONFIG[re.name]=re.value;
Storage.set(re.name,re.value);
});
layer.close();
}
小程序、uniapp、thinkPHP、Vue相互转换核心代码
最新推荐文章于 2023-03-21 14:36:36 发布