Browse Source

feat(富文本插件): 富文本插件demo测试

tall
wally 4 years ago
parent
commit
ed3d644a2e
  1. 2
      .eslintcache
  2. 8
      CHANGELOG.md
  3. 1
      package.json
  4. 3
      public/index.html
  5. 33
      src/mock/rich-text.js
  6. 6
      src/pages.json
  7. 3
      src/pages/index/index.vue
  8. 59
      src/pages/plugin-test/plugin-test.vue
  9. 73
      src/pages/rich-text/rich-text.vue
  10. 13
      src/utils/request.js
  11. 3
      vue.config.js
  12. 25
      yarn.lock

2
.eslintcache

@ -1 +1 @@
[{"/mnt/c/Users/Administrator/Documents/coding/ccsens/tall-mui-cli/commitlint.config.js":"1","/mnt/c/Users/Administrator/Documents/coding/ccsens/tall-mui-cli/src/main.js":"2","/mnt/c/Users/Administrator/Documents/coding/ccsens/tall-mui-cli/src/registerServiceWorker.js":"3","/mnt/c/Users/Administrator/Documents/coding/ccsens/tall-mui-cli/tailwind.config.js":"4"},{"size":85,"mtime":1623976024000,"results":"5","hashOfConfig":"6"},{"size":222,"mtime":1623976024081,"results":"7","hashOfConfig":"6"},{"size":882,"mtime":1623976024087,"results":"8","hashOfConfig":"6"},{"size":160,"mtime":1623976024089},{"filePath":"9","messages":"10","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"14qqz39",{"filePath":"11","messages":"12","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"13","messages":"14","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/mnt/c/Users/Administrator/Documents/coding/ccsens/tall-mui-cli/commitlint.config.js",[],"/mnt/c/Users/Administrator/Documents/coding/ccsens/tall-mui-cli/src/main.js",[],"/mnt/c/Users/Administrator/Documents/coding/ccsens/tall-mui-cli/src/registerServiceWorker.js",[]]
[{"/mnt/c/Users/Administrator/Documents/coding/ccsens/demo/tall-v3.0-demo/src/main.js":"1","/mnt/c/Users/Administrator/Documents/coding/ccsens/demo/tall-v3.0-demo/src/utils/request.js":"2"},{"size":335,"mtime":1624344979998,"results":"3","hashOfConfig":"4"},{"size":1742,"mtime":1624344980012,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"178d5hk",{"filePath":"8","messages":"9","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/mnt/c/Users/Administrator/Documents/coding/ccsens/demo/tall-v3.0-demo/src/main.js",[],"/mnt/c/Users/Administrator/Documents/coding/ccsens/demo/tall-v3.0-demo/src/utils/request.js",[]]

8
CHANGELOG.md

@ -1,4 +1,10 @@
# [0.1.0](https://gitee.com/mongos/uni-cli-template/compare/v1.0.1...v0.1.0) (2021-06-22)
# [0.1.0](https://gitee.com/mongos/uni-cli-template/compare/v1.0.1...v0.1.0) (2021-06-23)
### chore
范围|描述|commitId
--|--|--
- | uview-ui | [a9ea34b](https://gitee.com/mongos/uni-cli-template/commits/a9ea34b)
## [1.0.1](https://gitee.com/mongos/uni-cli-template/compare/c0f1deb...v1.0.1) (2021-06-22)
### 🔨 代码重构

1
package.json

@ -92,6 +92,7 @@
"@vue/cli-plugin-pwa": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"vue-cli-plugin-mock": "^1.0.3",
"@vue/eslint-config-prettier": "^6.0.0",
"babel-eslint": "^10.1.0",
"babel-plugin-import": "^1.11.0",

3
public/index.html

@ -23,6 +23,7 @@
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
</html>

33
src/mock/rich-text.js

@ -0,0 +1,33 @@
export default [
{
path: '/tasks',
handler: (req, res) => {
return res.json({
code: 200,
msg: 'ok',
success: true,
data: {
plugins: [
`<button onclick="location.href='https://www.tall.wiki/wl/1'">js打开物流页面</button>`,
`<a href="https://www.tall.wiki/wl/5">a链接打开现海园区</a>`,
`<div class="p-3 my-4 text-2xl bg-yellow-400 text-white" onclick="alert(123)">样式继承及简单脚本</div>`,
`<div class="p-3 my-4 text-2xl bg-red-400 text-white" onclick="openModal()">先是modal, 函数执行</div>
<div style="display: none" id="modal">modal</div>
<script>
function openModal() {
const modal = document.getElementById('modal');
if (modal.style.display === 'block') {
modal.style.display = 'none';
} else {
modal.style.display = 'block';
}
console.log('modal显示了');
}
</script>`,
],
},
});
},
},
];

6
src/pages.json

@ -11,6 +11,12 @@
"style": {
"navigationBarTitleText": "iframe-测试"
}
},
{
"path": "pages/rich-text/rich-text",
"style": {
"navigationBarTitleText": "rich-text 测试"
}
}
],
"globalStyle": {

3
src/pages/index/index.vue

@ -1,7 +1,8 @@
<template>
<view class="container p-4">
<view>
<u-button type="primary" size="default">iframe 验证</u-button>
<u-button type="primary" size="default" @tap="$u.route('/pages/plugin-test/plugin-test')">iframe 验证</u-button>
<u-button type="error" size="default" class="my-3" @tap="$u.route('/pages/rich-text/rich-text')">rich-text 验证</u-button>
</view>
</view>
</template>

59
src/pages/plugin-test/plugin-test.vue

@ -1,7 +1,62 @@
<template>
<view> iframe 验证 </view>
<view>
<view v-for="(item, index) in iframes" :key="index" style="height: 500rpx" class="p-1">
<!-- <web-view :src="item"></web-view> -->
<iframe :src="item" frameborder="0" class="block w-full h-full" :id="`iframe${index}`"></iframe>
</view>
</view>
</template>
<script>
export default {};
/* eslint-disable max-len */
const iframes = [
'https://uniapp.dcloud.io/static/web-view.html',
'https://baidu.com',
'https://uland.taobao.com/semm/tbsearch?refpid=mm_26632258_3504122_32554087&keyword=%E5%A5%B3%E8%A3%85&clk1=ad91ec4906f3ffe8328566a1bf604aef&upsId=ad91ec4906f3ffe8328566a1bf604aef',
'https://m.jd.com/',
'https://www.ccsens.com',
'https://www.tall.wiki/wl/1',
'https://h5.m.jd.com/active/yard-channel/index.html?themeId=24883&babelChannel=356440&innerLink=%5B%7B%22matId%22%3A%223203085%22%7D%2C%7B%22matId%22%3A%223205226%22%7D%5D&themeStyle=0&innerIndex=1',
'https://mitem.jd.hk/product/3205226.html?pdtk=ZenDw7dK%2FC8XmpuZbhgbkp%2BSbyLL5R0S14AvHWdeeAL2Z36jPKDzWg%2BYBNa0HgvE&_fd=jdm&sid=null',
'https://shop.m.jd.com/shopv2/mzpage?shopId=1000015205&venderId=1000015205&skuId=3205226&categoryId=1319_1523_7052&sceneval=2&jxsid=16243458685744852366&_fd=jdm&_fd=jdm',
'https://www.tall.wiki/wl/2',
'https://www.tall.wiki/wl/3',
'https://www.tall.wiki/wl/4',
'https://www.tall.wiki/wl/5',
'https://www.tall.wiki/wl/7',
'https://www.tall.wiki/wl/6',
];
/* eslint-enable max-len */
export default {
data() {
return { iframes, createdTime: 0, mountedTime: 0 };
},
created() {
this.createdTime = Date.now();
console.error('created:', new Date().toLocaleString());
},
mounted() {
this.mountedTime = Date.now();
console.error('mounted:', new Date().toLocaleString());
this.$nextTick(this.init);
},
methods: {
init() {
this.iframes.forEach((item, index) => {
const element = document.getElementById(`iframe${index}`);
element.addEventListener(
'load',
() => {
const now = Date.now();
console.error(`${index} ${item} 加载结束`, new Date().toLocaleString(), now - this.createdTime, now - this.mountedTime);
},
false,
);
});
},
},
};
</script>

73
src/pages/rich-text/rich-text.vue

@ -0,0 +1,73 @@
<template>
<view class="p-3">
<!-- <view v-if="!plugins">加载中...</view>
<template v-else> -->
<view id="container" class="my-3"></view>
<!-- </template> -->
</view>
</template>
<script>
export default {
data() {
return { plugins: null };
},
mounted() {
// window.openModal = function () {
// const modal = document.getElementById('modal');
// modal.style.display = 'block';
// alert('modal');
// };
this.getData();
},
methods: {
async getData() {
try {
const data = await this.$u.get('/tasks');
console.log(data);
this.plugins = [...data.plugins] || null;
this.renderDOM(this.plugins); // DOM
} catch (error) {
console.log('🚀 ~ file: rich-text.vue ~ line 33 ~ getData ~ error', error);
this.plugins = null;
}
},
/**
* 渲染DOM
* @param {Array | null} plugins 拿到的内置插件数据
*
* FIXME: 只处理了1个script标签的情况
* FIXME: 插件命名空间 作用域未处理
* FIXME: 插件关闭退出时, 应该移除相关的script代码
*/
renderDOM(plugins) {
if (!plugins || !plugins.length) return;
const element = document.getElementById('container');
// eslint-disable-next-line no-useless-escape
const reg = /<script\b[^>]*>([\s\S]*)<\/script>/gim;
let str = element.innerHTML;
for (let item of plugins) {
// console.log(reg.test(item), item.match(reg), RegExp.$1);
if (reg.test(item)) {
// code snippets script
const scriptElement = document.createElement('script');
const text = RegExp.$1;
try {
scriptElement.appendChild(document.createTextNode(text));
} catch (error) {
scriptElement.text = text;
}
document.body.appendChild(scriptElement); // script
str += item.replace(reg, ''); // script
} else {
str += `<div>${item}</div>`;
}
}
element.innerHTML = str;
},
},
};
</script>

13
src/utils/request.js

@ -1,5 +1,4 @@
const install = (Vue, vm) => {
console.log();
Vue.prototype.$u.http.setConfig({
baseUrl: '',
showLoading: true, // 是否显示请求中的loading
@ -14,21 +13,21 @@ const install = (Vue, vm) => {
Vue.prototype.$u.http.interceptor.request = config => {
// TODO: 如果在白名单里 则不需要加token
if (vm.$store.state.user.token) {
config.header.Authorization = `Bearer ${vm.$store.state.user.token}`;
}
// if (vm.$store.state.user.token) {
// config.header.Authorization = `Bearer ${vm.$store.state.user.token}`;
// }
return config;
};
// 响应拦截,如配置,每次请求结束都会执行本方法
Vue.prototype.$u.http.interceptor.response = res => {
if (res.code == 200) {
if (res.code === 200) {
// res为服务端返回值,可能有code,result等字段
// 这里对res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到
// 如果配置了originalData为true,请留意这里的返回值
return res.result;
} else if (res.code == 401) {
return res.data;
} else if (res.code === 401) {
// 假设201为token失效,这里跳转登录
vm.$u.toast('验证失败,请重新登录');
setTimeout(() => {

3
vue.config.js

@ -10,4 +10,7 @@ module.exports = {
// proxy: {}
},
configureWebpack: { plugins: [] },
pluginOptions: {
mock: { entry: './src/mock/rich-text.js', debug: true },
},
};

25
yarn.lock

@ -3188,7 +3188,7 @@ bn.js@^5.0.0, bn.js@^5.1.1:
resolved "https://registry.npm.taobao.org/bn.js/download/bn.js-5.2.0.tgz#358860674396c6997771a9d051fcc1b57d4ae002"
integrity sha1-NYhgZ0OWxpl3canQUfzBtX1K4AI=
body-parser@1.19.0:
body-parser@1.19.0, body-parser@^1.18.3:
version "1.19.0"
resolved "https://registry.npm.taobao.org/body-parser/download/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a"
integrity sha1-lrJwnlfJxOCab9Zqj9l5hE9p8Io=
@ -5689,6 +5689,16 @@ expect@^25.5.0:
jest-message-util "^25.5.0"
jest-regex-util "^25.2.6"
express-mock-restful@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/express-mock-restful/-/express-mock-restful-1.1.3.tgz#95ec62327f39d49914e7d015fc604d5c1deaab29"
integrity sha512-ghjTu9v4K8U/2GOx8j3CCo4JH6FCfeK9UvwbEPHZvdVBQvGd0NZXjkoss5p6F4npx0BuBQukftXnu1IHBTElgw==
dependencies:
body-parser "^1.18.3"
chalk "^2.4.1"
debug "^3.1.0"
path-to-regexp "^2.2.1"
express@^4.16.3, express@^4.17.1:
version "4.17.1"
resolved "https://registry.npm.taobao.org/express/download/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134"
@ -9825,6 +9835,11 @@ path-to-regexp@^1.1.1:
dependencies:
isarray "0.0.1"
path-to-regexp@^2.2.1:
version "2.4.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-2.4.0.tgz#35ce7f333d5616f1c1e1bfe266c3aba2e5b2e704"
integrity sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w==
path-type@^1.0.0:
version "1.1.0"
resolved "https://registry.npm.taobao.org/path-type/download/path-type-1.1.0.tgz?cache=0&sync_timestamp=1611752074264&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fpath-type%2Fdownload%2Fpath-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
@ -12891,6 +12906,14 @@ vue-cli-plugin-commitlint@~1.0.12:
resolved "https://registry.npm.taobao.org/vue-cli-plugin-commitlint/download/vue-cli-plugin-commitlint-1.0.12.tgz#176819170661f552497bad0458144fa9d55dc092"
integrity sha1-F2gZFwZh9VJJe60EWBRPqdVdwJI=
vue-cli-plugin-mock@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/vue-cli-plugin-mock/-/vue-cli-plugin-mock-1.0.3.tgz#5d31732c622a241239c640569f05b8bca4c660c6"
integrity sha512-SpOJKJ9JqcPT/zGJPewKNDLaLTeysVGe/QXfNIWHn9UGr72opxl/I5gXCJbpag910aFvCr5rC+qraC06tbqx9g==
dependencies:
express-mock-restful "^1.1.3"
memory-fs "^0.4.1"
vue-eslint-parser@^7.0.0:
version "7.6.0"
resolved "https://registry.nlark.com/vue-eslint-parser/download/vue-eslint-parser-7.6.0.tgz#01ea1a2932f581ff244336565d712801f8f72561"

Loading…
Cancel
Save