diff --git a/.hbuilderx/launch.json b/.hbuilderx/launch.json new file mode 100644 index 0000000..4ccd172 --- /dev/null +++ b/.hbuilderx/launch.json @@ -0,0 +1,20 @@ +{ + // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/ + // launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数 + "version" : "0.0", + "configurations" : [ + { + "app-plus" : { + "launchtype" : "local" + }, + "default" : { + "launchtype" : "local" + }, + "type" : "uniCloud" + }, + { + "playground" : "custom", + "type" : "uni-app:app-android" + } + ] +} diff --git a/ai1.png b/ai1.png deleted file mode 100644 index 3bcf4bd..0000000 Binary files a/ai1.png and /dev/null differ diff --git a/api/api.js b/api/api.js new file mode 100644 index 0000000..4e46a77 --- /dev/null +++ b/api/api.js @@ -0,0 +1,168 @@ +import request from "@/utils/request.js"; +import requesta from "@/utils/requesta.js"; + +/** + * 直播列表 + */ +export function live(data) { + return request.get("zhibo/live" ,data); +} +/** + * 直播详情 + */ +export function liveDetail(data) { + return request.get("zhibo/liveDetail" ,data); +} + + +/** + * 获取直播详情接口 + */ + + +/** + * 创建直播间 + */ +export function createPushLive(data) { + return request.post("zhibo/createPushLive", data); +} + +/** + * 关闭直播间 + */ +export function stopPushLive(data) { + return request.post("zhibo/stopPushLive", data); +} + + +/** + * 绑定用户client客户 + */ +export function bindUser(data) { + return request.post("zhibo/bindUser", data,{}); +} + + + +/** + * 加入直播间聊天室 + */ +export function joinChatRoom(data) { + return request.post("zhibo/joinChatRoom", data); +} + + +/** + * 直播间聊天室发言 + */ +export function sendGroupMessage(data) { + return request.post("zhibo/sendGroupMessage", data); +} + + + +//商品列表 +export function good(data) { + return requesta.get("product/spu/lst", data); +} + +/** + * 获取用户信息 + * + */ +export function getUserInfo() { + return request.get('user'); +} + + + +//关注 +export function getfans(id,data) { + return requesta.post('community/fans/'+id,data); +} + +//我关注的人 +export function getfocuslst(data) { + return requesta.post('community/focus/lst',data); +} + +//关注我的人 +export function getfanslst(data) { + return requesta.post('community/fans/lst',data); +} + +//用户送礼 +export function reward(data) { + return request.post('zhibo/reward',data); +} +//获取礼物 +export function rewardList(data) { + return requesta.get('zhibo/rewardList',data); +} + +//获取礼物 +export function giftList(data) { + return request.get('zhibo/giftList',data); +} + +//获取房间人数 +export function liveAudience(data) { + return request.get('zhibo/liveAudience',data); +} + +//获取用户余额 +export function getuser(data) { + return requesta.get('user',data); +} + + +//送礼 +export function sendGift(data) { + return request.post('zhibo/sendGift',data); +} + +/** + * 充值金额选择 + */ +export function getRechargeApi() { + return requesta.get("common/recharge_quota"); +} + +//历史直播记录 + +export function playbackList(data) { + return request.get("zhibo/playbackList",data); +} + +//获取直播回放详情 +export function playbackDetail(data) { + return request.get("zhibo/playbackDetail",data); +} +//获取观众关注主播状态 +export function getAjuser(data) { + return requesta.get("community/user/info/"+data); +} + +/** + * 滑块信息 + * @param {Object} data + */ +export function getAjcaptcha(data) { + return requesta.get("ajcaptcha", data, { + noAuth: true + }); +} + + + +/** + * 滑块验证 + * @param {Object} data + */ +export function ajcaptchaCheck(data) { + return requesta.post("ajcheck", data, { + noAuth: true + }); +} + + diff --git a/api/public.js b/api/public.js new file mode 100644 index 0000000..d4cae52 --- /dev/null +++ b/api/public.js @@ -0,0 +1,21 @@ +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- +import request from "@/utils/requesta.js"; + +export function getVersion() { + return request.get("version",{},{noAuth: true}); +} +export function commonAuth(data) { + return request.post( + "auth", data, { + noAuth: true + } + ); +} diff --git a/api/user.js b/api/user.js new file mode 100644 index 0000000..56e0b83 --- /dev/null +++ b/api/user.js @@ -0,0 +1,106 @@ +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- +import request from "@/utils/requesta.js"; + + +export function getAdminApplyListAPI(merId) { + return request.get(`admin/${merId}/lis_apply`); +} +/** + * 获取用户信息 + * + */ +export function getUserInfo() { + return request.get('user'); +} +/** + * 头像 + * + */ +export function editAvatar(data) { + return request.post('user/change/info', data); +} + +// 修改昵称 +export function updateInfo(data) { + return request.post('user/change/avatar', data); +} +/** + * h5用户登录 + * @param data object 用户账号密码 + */ +export function loginH5(data) { + return request.post("auth/login", data, { + noAuth: true + }); +} +/** + * h5用户手机号登录 + * @param data object 用户手机号 也只能 + */ +export function loginMobile(data) { + return request.post("auth/smslogin", data, { + noAuth: true + }); +} +/** + * h5用户手机号登录 + * @param data object 用户手机号 也只能 + */ +export function loginMpPhone(data) { + return request.post("auth/mp_phone", data, { + noAuth: true + }); +} +/** + * 验证码key + */ +export function getCodeApi() { + return request.get("verify_code", {}, { + noAuth: true + }); +} + +/** + * h5用户发送验证码 + * @param data object 用户手机号 + */ +export function registerVerify(data) { + return request.post("auth/verify", data, { + noAuth: true + }); +} +/** + * h5用户手机号注册 + * @param data object 用户手机号 验证码 密码 + */ +export function register(data) { + return request.post("auth/register", data, { + noAuth: true + }); +} + +/** + * 用户手机号修改密码 + * @param data object 用户手机号 验证码 密码 + */ +export function registerReset(data) { + return request.post("/register/reset", data, { + noAuth: true + }); +} +/** + * 用户手机号忘记密码 + */ +export function registerForget(data) { + return request.post("user/change_pwd", data, { + noAuth: true + }); +} diff --git a/components/emptyPage.vue b/components/emptyPage.vue new file mode 100644 index 0000000..0f2ba27 --- /dev/null +++ b/components/emptyPage.vue @@ -0,0 +1,45 @@ + + + + + diff --git a/components/gb-popup/gb-popup.vue b/components/gb-popup/gb-popup.vue new file mode 100644 index 0000000..12dcd71 --- /dev/null +++ b/components/gb-popup/gb-popup.vue @@ -0,0 +1,168 @@ + + + + + \ No newline at end of file diff --git a/components/jyf-parser/jyf-parser.vue b/components/jyf-parser/jyf-parser.vue new file mode 100644 index 0000000..6294c26 --- /dev/null +++ b/components/jyf-parser/jyf-parser.vue @@ -0,0 +1,815 @@ + + + + + + diff --git a/components/jyf-parser/libs/CssHandler.js b/components/jyf-parser/libs/CssHandler.js new file mode 100644 index 0000000..f286db3 --- /dev/null +++ b/components/jyf-parser/libs/CssHandler.js @@ -0,0 +1,111 @@ +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- +/* + 解析和匹配 Css 的选择器 + github:https://github.com/jin-yufeng/Parser + docs:https://jin-yufeng.github.io/Parser + author:JinYufeng + update:2020/03/15 +*/ +var cfg = require('./config.js'); +class CssHandler { + constructor(tagStyle) { + var styles = Object.assign({}, cfg.userAgentStyles); + for (var item in tagStyle) + styles[item] = (styles[item] ? styles[item] + ';' : '') + tagStyle[item]; + this.styles = styles; + } + getStyle = data => this.styles = new CssParser(data, this.styles).parse(); + match(name, attrs) { + var tmp, matched = (tmp = this.styles[name]) ? tmp + ';' : ''; + if (attrs.class) { + var items = attrs.class.split(' '); + for (var i = 0, item; item = items[i]; i++) + if (tmp = this.styles['.' + item]) + matched += tmp + ';'; + } + if (tmp = this.styles['#' + attrs.id]) + matched += tmp + ';'; + return matched; + } +} +module.exports = CssHandler; +class CssParser { + constructor(data, init) { + this.data = data; + this.floor = 0; + this.i = 0; + this.list = []; + this.res = init; + this.state = this.Space; + } + parse() { + for (var c; c = this.data[this.i]; this.i++) + this.state(c); + return this.res; + } + section = () => this.data.substring(this.start, this.i); + isLetter = c => (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); + // 状态机 + Space(c) { + if (c == '.' || c == '#' || this.isLetter(c)) { + this.start = this.i; + this.state = this.Name; + } else if (c == '/' && this.data[this.i + 1] == '*') + this.Comment(); + else if (!cfg.blankChar[c] && c != ';') + this.state = this.Ignore; + } + Comment() { + this.i = this.data.indexOf('*/', this.i) + 1; + if (!this.i) this.i = this.data.length; + this.state = this.Space; + } + Ignore(c) { + if (c == '{') this.floor++; + else if (c == '}' && !--this.floor) this.state = this.Space; + } + Name(c) { + if (cfg.blankChar[c]) { + this.list.push(this.section()); + this.state = this.NameSpace; + } else if (c == '{') { + this.list.push(this.section()); + this.Content(); + } else if (c == ',') { + this.list.push(this.section()); + this.Comma(); + } else if (!this.isLetter(c) && (c < '0' || c > '9') && c != '-' && c != '_') + this.state = this.Ignore; + } + NameSpace(c) { + if (c == '{') this.Content(); + else if (c == ',') this.Comma(); + else if (!cfg.blankChar[c]) this.state = this.Ignore; + } + Comma() { + while (cfg.blankChar[this.data[++this.i]]); + if (this.data[this.i] == '{') this.Content(); + else { + this.start = this.i--; + this.state = this.Name; + } + } + Content() { + this.start = ++this.i; + if ((this.i = this.data.indexOf('}', this.i)) == -1) this.i = this.data.length; + var content = this.section(); + for (var i = 0, item; item = this.list[i++];) + if (this.res[item]) this.res[item] += ';' + content; + else this.res[item] = content; + this.list = []; + this.state = this.Space; + } +} diff --git a/components/jyf-parser/libs/MpHtmlParser.js b/components/jyf-parser/libs/MpHtmlParser.js new file mode 100644 index 0000000..30c59e9 --- /dev/null +++ b/components/jyf-parser/libs/MpHtmlParser.js @@ -0,0 +1,586 @@ +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- +/* + 将 html 解析为适用于小程序 rich-text 的 DOM 结构 + github:https://github.com/jin-yufeng/Parser + docs:https://jin-yufeng.github.io/Parser + author:JinYufeng + update:2020/04/13 +*/ +var cfg = require('./config.js'), + blankChar = cfg.blankChar, + CssHandler = require('./CssHandler.js'), + { + screenWidth, + system + } = wx.getSystemInfoSync(); +// #ifdef MP-BAIDU || MP-ALIPAY || MP-TOUTIAO +var entities = { + lt: '<', + gt: '>', + amp: '&', + quot: '"', + apos: "'", + nbsp: '\xA0', + ensp: '\u2002', + emsp: '\u2003', + ndash: '–', + mdash: '—', + middot: '·', + lsquo: '‘', + rsquo: '’', + ldquo: '“', + rdquo: '”', + bull: '•', + hellip: '…', + permil: '‰', + copy: '©', + reg: '®', + trade: '™', + times: '×', + divide: '÷', + cent: '¢', + pound: '£', + yen: '¥', + euro: '€', + sect: '§' +}; +// #endif +var emoji; // emoji 补丁包 https://jin-yufeng.github.io/Parser/#/instructions?id=emoji +class MpHtmlParser { + constructor(data, options = {}) { + this.attrs = {}; + this.compress = options.compress; + this.CssHandler = new CssHandler(options.tagStyle, screenWidth); + this.data = data; + this.domain = options.domain; + this.DOM = []; + this.i = this.start = this.audioNum = this.imgNum = this.videoNum = 0; + this.protocol = this.domain && this.domain.includes('://') ? this.domain.split('://')[0] : ''; + this.state = this.Text; + this.STACK = []; + this.useAnchor = options.useAnchor; + this.xml = options.xml; + } + parse() { + if (emoji) this.data = emoji.parseEmoji(this.data); + for (var c; c = this.data[this.i]; this.i++) + this.state(c); + if (this.state == this.Text) this.setText(); + while (this.STACK.length) this.popNode(this.STACK.pop()); + // #ifdef MP-BAIDU || MP-TOUTIAO + // 将顶层标签的一些样式提取出来给 rich-text + (function f(ns) { + for (var i = ns.length, n; n = ns[--i];) { + if (n.type == 'text') continue; + if (!n.c) { + var style = n.attrs.style; + if (style) { + var j, k, res; + if ((j = style.indexOf('display')) != -1) + res = style.substring(j, (k = style.indexOf(';', j)) == -1 ? style.length : k); + if ((j = style.indexOf('float')) != -1) + res += ';' + style.substring(j, (k = style.indexOf(';', j)) == -1 ? style.length : k); + n.attrs.contain = res; + } + } else f(n.children); + } + })(this.DOM); + // #endif + if (this.DOM.length) { + this.DOM[0].PoweredBy = 'Parser'; + if (this.title) this.DOM[0].title = this.title; + } + return this.DOM; + } + // 设置属性 + setAttr() { + var name = this.getName(this.attrName); + if (cfg.trustAttrs[name]) { + if (!this.attrVal) { + if (cfg.boolAttrs[name]) this.attrs[name] = 'T'; + } else if (name == 'src') this.attrs[name] = this.getUrl(this.attrVal.replace(/&/g, '&')); + else this.attrs[name] = this.attrVal; + } + this.attrVal = ''; + while (blankChar[this.data[this.i]]) this.i++; + if (this.isClose()) this.setNode(); + else { + this.start = this.i; + this.state = this.AttrName; + } + } + // 设置文本节点 + setText() { + var back, text = this.section(); + if (!text) return; + text = (cfg.onText && cfg.onText(text, () => back = true)) || text; + if (back) { + this.data = this.data.substr(0, this.start) + text + this.data.substr(this.i); + let j = this.start + text.length; + for (this.i = this.start; this.i < j; this.i++) this.state(this.data[this.i]); + return; + } + if (!this.pre) { + // 合并空白符 + var tmp = []; + for (let i = text.length, c; c = text[--i];) + if (!blankChar[c] || (!blankChar[tmp[0]] && (c = ' '))) tmp.unshift(c); + text = tmp.join(''); + if (text == ' ') return; + } + // 处理实体 + var siblings = this.siblings(), + i = -1, + j, en; + while (1) { + if ((i = text.indexOf('&', i + 1)) == -1) break; + if ((j = text.indexOf(';', i + 2)) == -1) break; + if (text[i + 1] == '#') { + en = parseInt((text[i + 2] == 'x' ? '0' : '') + text.substring(i + 2, j)); + if (!isNaN(en)) text = text.substr(0, i) + String.fromCharCode(en) + text.substring(j + 1); + } else { + en = text.substring(i + 1, j); + // #ifdef MP-WEIXIN || MP-QQ || APP-PLUS + if (en == 'nbsp') text = text.substr(0, i) + '\xA0' + text.substr(j + 1); // 解决   失效 + else if (en != 'lt' && en != 'gt' && en != 'amp' && en != 'ensp' && en != 'emsp' && en != 'quot' && en != 'apos') { + i && siblings.push({ + type: 'text', + text: text.substr(0, i) + }) + siblings.push({ + type: 'text', + text: `&${en};`, + en: 1 + }) + text = text.substr(j + 1); + i = -1; + } + // #endif + // #ifdef MP-BAIDU || MP-ALIPAY || MP-TOUTIAO + if (entities[en]) text = text.substr(0, i) + entities[en] + text.substr(j + 1); + // #endif + } + } + text && siblings.push({ + type: 'text', + text + }) + } + // 设置元素节点 + setNode() { + var node = { + name: this.tagName.toLowerCase(), + attrs: this.attrs + }, + close = cfg.selfClosingTags[node.name] || (this.xml && this.data[this.i] == '/'); + this.attrs = {}; + if (!cfg.ignoreTags[node.name]) { + this.matchAttr(node); + if (!close) { + node.children = []; + if (node.name == 'pre' && cfg.highlight) { + this.remove(node); + this.pre = node.pre = true; + } + this.siblings().push(node); + this.STACK.push(node); + } else if (!cfg.filter || cfg.filter(node, this) != false) + this.siblings().push(node); + } else { + if (!close) this.remove(node); + else if (node.name == 'source') { + var parent = this.STACK[this.STACK.length - 1], + attrs = node.attrs; + if (parent && attrs.src) + if (parent.name == 'video' || parent.name == 'audio') + parent.attrs.source.push(attrs.src); + else { + var i, media = attrs.media; + if (parent.name == 'picture' && !parent.attrs.src && !(attrs.src.indexOf('.webp') && system.includes('iOS')) && + (!media || (media.includes('px') && + (((i = media.indexOf('min-width')) != -1 && (i = media.indexOf(':', i + 8)) != -1 && screenWidth > parseInt( + media.substr(i + 1))) || + ((i = media.indexOf('max-width')) != -1 && (i = media.indexOf(':', i + 8)) != -1 && screenWidth < parseInt( + media.substr(i + 1))))))) + parent.attrs.src = attrs.src; + } + } else if (node.name == 'base' && !this.domain) this.domain = node.attrs.href; + } + if (this.data[this.i] == '/') this.i++; + this.start = this.i + 1; + this.state = this.Text; + } + // 移除标签 + remove(node) { + var name = node.name, + j = this.i; + while (1) { + if ((this.i = this.data.indexOf('', this.i)) == -1) this.i = this.data.length; + // 处理 svg + if (name == 'svg') { + var src = this.data.substring(j, this.i + 1); + if (!node.attrs.xmlns) src = ' xmlns="http://www.w3.org/2000/svg"' + src; + var i = j; + while (this.data[j] != '<') j--; + src = this.data.substring(j, i) + src; + var parent = this.STACK[this.STACK.length - 1]; + if (node.attrs.width == '100%' && parent && (parent.attrs.style || '').includes('inline')) + parent.attrs.style = 'width:300px;max-width:100%;' + parent.attrs.style; + this.siblings().push({ + name: 'img', + attrs: { + src: 'data:image/svg+xml;utf8,' + src.replace(/#/g, '%23'), + ignore: 'T' + } + }) + } + return; + } + } + } + // 处理属性 + matchAttr(node) { + var attrs = node.attrs, + style = this.CssHandler.match(node.name, attrs, node) + (attrs.style || ''), + styleObj = {}; + if (attrs.id) { + if (this.compress & 1) attrs.id = void 0; + else if (this.useAnchor) this.bubble(); + } + if ((this.compress & 2) && attrs.class) attrs.class = void 0; + switch (node.name) { + case 'img': + if (attrs['data-src']) { + attrs.src = attrs.src || attrs['data-src']; + attrs['data-src'] = void 0; + } + if (attrs.src && !attrs.ignore) { + if (this.bubble()) attrs.i = (this.imgNum++).toString(); + else attrs.ignore = 'T'; + } + break; + case 'a': + case 'ad': + // #ifdef APP-PLUS + case 'iframe': + case 'embed': + // #endif + this.bubble(); + break; + case 'font': + if (attrs.color) { + styleObj['color'] = attrs.color; + attrs.color = void 0; + } + if (attrs.face) { + styleObj['font-family'] = attrs.face; + attrs.face = void 0; + } + if (attrs.size) { + var size = parseInt(attrs.size); + if (size < 1) size = 1; + else if (size > 7) size = 7; + var map = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large']; + styleObj['font-size'] = map[size - 1]; + attrs.size = void 0; + } + break; + case 'video': + case 'audio': + if (!attrs.id) attrs.id = node.name + (++this[`${node.name}Num`]); + else this[`${node.name}Num`]++; + if (node.name == 'video') { + if (attrs.width) { + style = `width:${parseFloat(attrs.width) + (attrs.width.includes('%') ? '%' : 'px')};${style}`; + attrs.width = void 0; + } + if (attrs.height) { + style = `height:${parseFloat(attrs.height) + (attrs.height.includes('%') ? '%' : 'px')};${style}`; + attrs.height = void 0; + } + if (this.videoNum > 3) node.lazyLoad = true; + } + attrs.source = []; + if (attrs.src) attrs.source.push(attrs.src); + if (!attrs.controls && !attrs.autoplay) + console.warn(`存在没有 controls 属性的 ${node.name} 标签,可能导致无法播放`, node); + this.bubble(); + break; + case 'td': + case 'th': + if (attrs.colspan || attrs.rowspan) + for (var k = this.STACK.length, item; item = this.STACK[--k];) + if (item.name == 'table') { + item.c = void 0; + break; + } + } + if (attrs.align) { + styleObj['text-align'] = attrs.align; + attrs.align = void 0; + } + // 压缩 style + var styles = style.replace(/"/g, '"').replace(/&/g, '&').split(';'); + style = ''; + for (var i = 0, len = styles.length; i < len; i++) { + var info = styles[i].split(':'); + if (info.length < 2) continue; + let key = info[0].trim().toLowerCase(), + value = info.slice(1).join(':').trim(); + if (value.includes('-webkit') || value.includes('-moz') || value.includes('-ms') || value.includes('-o') || value + .includes( + 'safe')) + style += `;${key}:${value}`; + else if (!styleObj[key] || value.includes('import') || !styleObj[key].includes('import')) + styleObj[key] = value; + } + if (node.name == 'img' && parseInt(styleObj.width || attrs.width) > screenWidth) + styleObj.height = 'auto'; + for (var key in styleObj) { + var value = styleObj[key]; + if (key.includes('flex') || key == 'order' || key == 'self-align') node.c = 1; + // 填充链接 + if (value.includes('url')) { + var j = value.indexOf('('); + if (j++ != -1) { + while (value[j] == '"' || value[j] == "'" || blankChar[value[j]]) j++; + value = value.substr(0, j) + this.getUrl(value.substr(j)); + } + } + // 转换 rpx + else if (value.includes('rpx')) + value = value.replace(/[0-9.]+\s*rpx/g, $ => parseFloat($) * screenWidth / 750 + 'px'); + else if (key == 'white-space' && value.includes('pre')) + this.pre = node.pre = true; + style += `;${key}:${value}`; + } + style = style.substr(1); + if (style) attrs.style = style; + } + // 节点出栈处理 + popNode(node) { + // 空白符处理 + if (node.pre) { + node.pre = this.pre = void 0; + for (let i = this.STACK.length; i--;) + if (this.STACK[i].pre) + this.pre = true; + } + if (node.name == 'head' || (cfg.filter && cfg.filter(node, this) == false)) + return this.siblings().pop(); + var attrs = node.attrs; + // 替换一些标签名 + if (node.name == 'picture') { + node.name = 'img'; + if (!attrs.src && (node.children[0] || '').name == 'img') + attrs.src = node.children[0].attrs.src; + if (attrs.src && !attrs.ignore) + attrs.i = (this.imgNum++).toString(); + return node.children = void 0; + } + if (cfg.blockTags[node.name]) node.name = 'div'; + else if (!cfg.trustTags[node.name]) node.name = 'span'; + // 处理列表 + if (node.c) { + if (node.name == 'ul') { + var floor = 1; + for (let i = this.STACK.length; i--;) + if (this.STACK[i].name == 'ul') floor++; + if (floor != 1) + for (let i = node.children.length; i--;) + node.children[i].floor = floor; + } else if (node.name == 'ol') { + for (let i = 0, num = 1, child; child = node.children[i++];) + if (child.name == 'li') { + child.type = 'ol'; + child.num = ((num, type) => { + if (type == 'a') return String.fromCharCode(97 + (num - 1) % 26); + if (type == 'A') return String.fromCharCode(65 + (num - 1) % 26); + if (type == 'i' || type == 'I') { + num = (num - 1) % 99 + 1; + var one = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'], + ten = ['X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'], + res = (ten[Math.floor(num / 10) - 1] || '') + (one[num % 10 - 1] || ''); + if (type == 'i') return res.toLowerCase(); + return res; + } + return num; + })(num++, attrs.type) + '.'; + } + } + } + // 处理表格的边框 + if (node.name == 'table') { + var padding = attrs.cellpadding, + spacing = attrs.cellspacing, + border = attrs.border; + if (node.c) { + this.bubble(); + if (!padding) padding = 2; + if (!spacing) spacing = 2; + } + if (border) attrs.style = `border:${border}px solid gray;${attrs.style || ''}`; + if (spacing) attrs.style = `border-spacing:${spacing}px;${attrs.style || ''}`; + if (border || padding) + (function f(ns) { + for (var i = 0, n; n = ns[i]; i++) { + if (n.name == 'th' || n.name == 'td') { + if (border) n.attrs.style = `border:${border}px solid gray;${n.attrs.style}`; + if (padding) n.attrs.style = `padding:${padding}px;${n.attrs.style}`; + } else f(n.children || []); + } + })(node.children) + } + this.CssHandler.pop && this.CssHandler.pop(node); + // 自动压缩 + if (node.name == 'div' && !Object.keys(attrs).length) { + var siblings = this.siblings(); + if (node.children.length == 1 && node.children[0].name == 'div') + siblings[siblings.length - 1] = node.children[0]; + } + } + // 工具函数 + bubble() { + for (var i = this.STACK.length, item; item = this.STACK[--i];) { + if (cfg.richOnlyTags[item.name]) { + if (item.name == 'table' && !Object.hasOwnProperty.call(item, 'c')) item.c = 1; + return false; + } + item.c = 1; + } + return true; + } + getName = val => this.xml ? val : val.toLowerCase(); + getUrl(url) { + if (url[0] == '/') { + if (url[1] == '/') url = this.protocol + ':' + url; + else if (this.domain) url = this.domain + url; + } else if (this.domain && url.indexOf('data:') != 0 && !url.includes('://')) + url = this.domain + '/' + url; + return url; + } + isClose = () => this.data[this.i] == '>' || (this.data[this.i] == '/' && this.data[this.i + 1] == '>'); + section = () => this.data.substring(this.start, this.i); + siblings = () => this.STACK.length ? this.STACK[this.STACK.length - 1].children : this.DOM; + // 状态机 + Text(c) { + if (c == '<') { + var next = this.data[this.i + 1], + isLetter = c => (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); + if (isLetter(next)) { + this.setText(); + this.start = this.i + 1; + this.state = this.TagName; + } else if (next == '/') { + this.setText(); + if (isLetter(this.data[++this.i + 1])) { + this.start = this.i + 1; + this.state = this.EndTag; + } else + this.Comment(); + } else if (next == '!') { + this.setText(); + this.Comment(); + } + } + } + Comment() { + var key; + if (this.data.substring(this.i + 2, this.i + 4) == '--') key = '-->'; + else if (this.data.substring(this.i + 2, this.i + 9) == '[CDATA[') key = ']]>'; + else key = '>'; + if ((this.i = this.data.indexOf(key, this.i + 2)) == -1) this.i = this.data.length; + else this.i += key.length - 1; + this.start = this.i + 1; + this.state = this.Text; + } + TagName(c) { + if (blankChar[c]) { + this.tagName = this.section(); + while (blankChar[this.data[this.i]]) this.i++; + if (this.isClose()) this.setNode(); + else { + this.start = this.i; + this.state = this.AttrName; + } + } else if (this.isClose()) { + this.tagName = this.section(); + this.setNode(); + } + } + AttrName(c) { + var blank = blankChar[c]; + if (blank) { + this.attrName = this.section(); + c = this.data[this.i]; + } + if (c == '=') { + if (!blank) this.attrName = this.section(); + while (blankChar[this.data[++this.i]]); + this.start = this.i--; + this.state = this.AttrValue; + } else if (blank) this.setAttr(); + else if (this.isClose()) { + this.attrName = this.section(); + this.setAttr(); + } + } + AttrValue(c) { + if (c == '"' || c == "'") { + this.start++; + if ((this.i = this.data.indexOf(c, this.i + 1)) == -1) return this.i = this.data.length; + this.attrVal = this.section(); + this.i++; + } else { + for (; !blankChar[this.data[this.i]] && !this.isClose(); this.i++); + this.attrVal = this.section(); + } + this.setAttr(); + } + EndTag(c) { + if (blankChar[c] || c == '>' || c == '/') { + var name = this.getName(this.section()); + for (var i = this.STACK.length; i--;) + if (this.STACK[i].name == name) break; + if (i != -1) { + var node; + while ((node = this.STACK.pop()).name != name); + this.popNode(node); + } else if (name == 'p' || name == 'br') + this.siblings().push({ + name, + attrs: {} + }); + this.i = this.data.indexOf('>', this.i); + this.start = this.i + 1; + if (this.i == -1) this.i = this.data.length; + else this.state = this.Text; + } + } +} +module.exports = MpHtmlParser; diff --git a/components/jyf-parser/libs/config.js b/components/jyf-parser/libs/config.js new file mode 100644 index 0000000..c7985ad --- /dev/null +++ b/components/jyf-parser/libs/config.js @@ -0,0 +1,89 @@ +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- +/* 配置文件 */ +// #ifdef MP-WEIXIN +const canIUse = wx.canIUse('editor'); // 高基础库标识,用于兼容 +// #endif +module.exports = { + // 过滤器函数 + filter: null, + // 代码高亮函数 + highlight: null, + // 文本处理函数 + onText: null, + blankChar: makeMap(' ,\xA0,\t,\r,\n,\f'), + // 块级标签,将被转为 div + blockTags: makeMap('address,article,aside,body,caption,center,cite,footer,header,html,nav,section' + ( + // #ifdef MP-WEIXIN + canIUse ? '' : + // #endif + ',pre')), + // 将被移除的标签 + ignoreTags: makeMap( + 'area,base,basefont,canvas,command,frame,input,isindex,keygen,link,map,meta,param,script,source,style,svg,textarea,title,track,use,wbr' + // #ifdef MP-WEIXIN + + (canIUse ? ',rp' : '') + // #endif + // #ifndef APP-PLUS + + ',embed,iframe' + // #endif + ), + // 只能被 rich-text 显示的标签 + richOnlyTags: makeMap('a,colgroup,fieldset,legend,picture,table' + // #ifdef MP-WEIXIN + + (canIUse ? ',bdi,bdo,caption,rt,ruby' : '') + // #endif + ), + // 自闭合的标签 + selfClosingTags: makeMap( + 'area,base,basefont,br,col,circle,ellipse,embed,frame,hr,img,input,isindex,keygen,line,link,meta,param,path,polygon,rect,source,track,use,wbr' + ), + // 信任的属性 + trustAttrs: makeMap( + 'align,alt,app-id,author,autoplay,border,cellpadding,cellspacing,class,color,colspan,controls,data-src,dir,face,height,href,id,ignore,loop,media,muted,name,path,poster,rowspan,size,span,src,start,style,type,unit-id,width,xmlns' + ), + // bool 型的属性 + boolAttrs: makeMap('autoplay,controls,ignore,loop,muted'), + // 信任的标签 + trustTags: makeMap( + 'a,abbr,ad,audio,b,blockquote,br,code,col,colgroup,dd,del,dl,dt,div,em,fieldset,h1,h2,h3,h4,h5,h6,hr,i,img,ins,label,legend,li,ol,p,q,source,span,strong,sub,sup,table,tbody,td,tfoot,th,thead,tr,title,ul,video' + // #ifdef MP-WEIXIN + + (canIUse ? ',bdi,bdo,caption,pre,rt,ruby' : '') + // #endif + // #ifdef APP-PLUS + + ',embed,iframe' + // #endif + ), + // 默认的标签样式 + userAgentStyles: { + address: 'font-style:italic', + big: 'display:inline;font-size:1.2em', + blockquote: 'background-color:#f6f6f6;border-left:3px solid #dbdbdb;color:#6c6c6c;padding:5px 0 5px 10px', + caption: 'display:table-caption;text-align:center', + center: 'text-align:center', + cite: 'font-style:italic', + dd: 'margin-left:40px', + img: 'max-width:100%', + mark: 'background-color:yellow', + picture: 'max-width:100%', + pre: 'font-family:monospace;white-space:pre;overflow:scroll', + s: 'text-decoration:line-through', + small: 'display:inline;font-size:0.8em', + u: 'text-decoration:underline' + } +} + +function makeMap(str) { + var map = {}, + list = str.split(','); + for (var i = list.length; i--;) + map[list[i]] = true; + return map; +} diff --git a/components/jyf-parser/libs/handler.sjs b/components/jyf-parser/libs/handler.sjs new file mode 100644 index 0000000..e8743fa --- /dev/null +++ b/components/jyf-parser/libs/handler.sjs @@ -0,0 +1,44 @@ +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- +var inlineTags = { + abbr: 1, + b: 1, + big: 1, + code: 1, + del: 1, + em: 1, + i: 1, + ins: 1, + label: 1, + q: 1, + small: 1, + span: 1, + strong: 1 +} +export default { + // 从顶层标签的样式中取出一些给 rich-text + getStyle: function(style) { + if (style) { + var i, j, res = ''; + if ((i = style.indexOf('display')) != -1) + res = style.substring(i, (j = style.indexOf(';', i)) == -1 ? style.length : j); + if ((i = style.indexOf('float')) != -1) + res += ';' + style.substring(i, (j = style.indexOf(';', i)) == -1 ? style.length : j); + return res; + } + }, + getNode: function(item) { + return [item]; + }, + // 是否通过 rich-text 显示 + useRichText: function(item) { + return !item.c && !inlineTags[item.name] && (item.attrs.style || '').indexOf('display:inline') == -1; + } +} diff --git a/components/jyf-parser/libs/handler.wxs b/components/jyf-parser/libs/handler.wxs new file mode 100644 index 0000000..afaf0bc --- /dev/null +++ b/components/jyf-parser/libs/handler.wxs @@ -0,0 +1,53 @@ +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- +var inlineTags = { + abbr: 1, + b: 1, + big: 1, + code: 1, + del: 1, + em: 1, + i: 1, + ins: 1, + label: 1, + q: 1, + small: 1, + span: 1, + strong: 1 +} +module.exports = { + // 从顶层标签的样式中取出一些给 rich-text + getStyle: function(style) { + if (style) { + var i, j, res = ''; + if ((i = style.indexOf('display')) != -1) + res = style.substring(i, (j = style.indexOf(';', i)) == -1 ? style.length : j); + if ((i = style.indexOf('float')) != -1) + res += ';' + style.substring(i, (j = style.indexOf(';', i)) == -1 ? style.length : j); + return res; + } + }, + // 处理懒加载 + getNode: function(item, imgLoad) { + if (!imgLoad && item.attrs.i != '0') { + var img = { + name: 'img', + attrs: JSON.parse(JSON.stringify(item.attrs)) + } + delete img.attrs.src; + img.attrs.style += ';width:20px;height:20px'; + return [img]; + } else return [item]; + }, + // 是否通过 rich-text 显示 + useRichText: function(item) { + return !item.c && !inlineTags[item.name] && (item.attrs.style || '').indexOf('display:inline') == -1; + } +} diff --git a/components/jyf-parser/libs/trees.vue b/components/jyf-parser/libs/trees.vue new file mode 100644 index 0000000..c2ea476 --- /dev/null +++ b/components/jyf-parser/libs/trees.vue @@ -0,0 +1,485 @@ + +