Initial commit

This commit is contained in:
admin
2025-12-08 14:39:07 +08:00
commit 9d4f78656b
782 changed files with 66418 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# 模板
这是一个插件模板,需要开发插件时,可以从这个模板开始

View File

@@ -0,0 +1,65 @@
/**
* @description 插件构建文件模板
*/
module.exports = {
/**
* @description 入口文件
* @type {String}
* @default 'index.js'
*/
main: 'index.js',
/**
* @description 支持的平台
* @type {String[]}
* @default ['mp-weixin','mp-qq','mp-baidu','mp-alipay','mp-toutiao','uni-app']
*/
platform: ['mp-weixin', 'mp-qq', 'mp-baidu', 'mp-alipay', 'mp-toutiao', 'uni-app'],
/**
* @description 要被添加到模板文件中的标签(将被添加到 src/node/node.wxml
* 必须要有 wx:if 表明什么情况下使用该标签
* n 表示标签结构体,<node> 标签用于递归显示子节点(可参考源文件中的写法)
* @type {String}
*/
template: '',
/**
* @description 用于处理模板中事件的方法(将被添加到 src/node/node.js
* 需要触发顶层组件的事件请使用 this.root.triggerEvent
* @type {Object}
*/
methods: {
},
/**
* @description 用于模板文件的 css 样式(将被添加到 src/node/node.wxss
* @type {String}
*/
style: '',
/**
* @description 要被引入到模板文件的 css 文件路径(将被添加到 src/node/node.wxss
* @type {String|String[]}
*/
import: [],
/**
* @description 在模板中需要使用的组件或插件列表(将被添加到 src/node/node.json
* @type {Object}
*/
usingComponents: {
},
/**
* @description 自定义文件处理器
* 如果上述处理还无法满足要求,可以在此方法中进行处理
* 所有 src 目录下的文件和本插件目录下的文件都会经过此方法的处理
* @param {Vinyl} file 关于该文件对象的格式可参考 https://github.com/gulpjs/vinyl#instance-methods
* @param {String} platform 平台
*/
handler (file, platform) {
let content = file.contents.toString()
// 进行处理
if (platform === 'xxx') {
content = content.replace('aaa', 'bbb')
}
file.contents = Buffer.from(content)
}
}

View File

@@ -0,0 +1,67 @@
/**
* @fileoverview 插件入口文件模板
*/
const data = {} // 全局数据
/**
* @description 组件被创建时将实例化插件
* @param {Component} vm 组件实例
*/
function Plugin (vm) {
this.vm = vm // 保存实例在其他周期使用
this.compData = {} // 仅在单个组件中使用的数据
data.xxx = 'xxx' // 记录全局数据
}
/**
* @description html 数据更新时触发
* @param {string} content 要更新的 html 字符串
* @param {object} config 解析配置
* @returns {string|void} 如果要对 html 字符串进行一些预处理,则返回处理后的字符串
*/
Plugin.prototype.onUpdate = function (content, config) {
config.ignoreTags.xxx = true // 移除 xxx 标签
// 对 html 内容进行预处理并返回修改,没有修改则不需要返回
return content
}
/**
* @description 解析到一个标签时触发
* @param {object} node 标签
* @param {object} parser 解析器实例
* @returns {boolean|void} 如果返回 false 将移除该标签
*/
Plugin.prototype.onParse = function (node, parser) {
// 处理文本标签
if (node.type === 'text') {
// node.text 文本内容
} else {
// 处理元素标签
// node.name 标签名
// node.attrs 属性列表
// node.children 子节点(非自闭合标签有)
if (node.name === 'xxx') {
parser.expose() // 如果该标签不能被 rich-text 包含,需要调用此方法暴露出来
// parser.options 组件传入的一些解析属性
// parser.stack 可以从栈中获取祖先节点
}
}
}
/**
* @description dom 树加载完毕时触发load 事件)
*/
Plugin.prototype.onLoad = function () {
// 可以获取媒体 context 对象等
}
/**
* @description 组件被移除时触发
*/
Plugin.prototype.onDetached = function () {
// 可以释放一些必要的资源(计时器等)
}
module.exports = Plugin