diff --git a/loaders/injectComponent/index.d.ts b/loaders/injectComponent/index.d.ts deleted file mode 100644 index 2ebcbb9..0000000 --- a/loaders/injectComponent/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export default function (source: string): string; diff --git a/loaders/injectComponent/index.js b/loaders/injectComponent/index.js deleted file mode 100644 index ec3adfa..0000000 --- a/loaders/injectComponent/index.js +++ /dev/null @@ -1,8 +0,0 @@ - -'use strict' - -if (process.env.NODE_ENV === 'production') { - module.exports = require('./taro-inject-component-loader.cjs.production.min.js') -} else { - module.exports = require('./taro-inject-component-loader.cjs.development.js') -} diff --git a/loaders/injectComponent/taro-inject-component-loader.cjs.development.js b/loaders/injectComponent/taro-inject-component-loader.cjs.development.js deleted file mode 100644 index b27e431..0000000 --- a/loaders/injectComponent/taro-inject-component-loader.cjs.development.js +++ /dev/null @@ -1,298 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { value: true }); - -function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } - -var generate = _interopDefault(require('@babel/generator')); -var traverse = _interopDefault(require('@babel/traverse')); -var utils = _interopDefault(require('@babel/types')); -var parser = require('@babel/parser'); -var loaderUtils = require('loader-utils'); -var schemaUtils = require('schema-utils'); - -var schema = { - type: 'object', - properties: { - importPath: { - type: 'string' - }, - isPage: { - "instanceof": 'Function' - }, - componentName: { - type: 'string' - } - }, - additionalProperties: false -}; -function index (source) { - // @ts-ignore - var webpackEnv = this; - var options = loaderUtils.getOptions(webpackEnv); - schemaUtils.validate(schema, options, { - name: 'taro-inject-component-loader' - }); - - var _ref = options || {}, - _ref$importPath = _ref.importPath, - importPath = _ref$importPath === void 0 ? '' : _ref$importPath, - _ref$componentName = _ref.componentName, - componentName = _ref$componentName === void 0 ? 'WebpackInjected' : _ref$componentName, - _ref$isPage = _ref.isPage, - isPage = _ref$isPage === void 0 ? defaultJudgePage : _ref$isPage; // 获取原始文件地址 - - - var filePath = webpackEnv.resourcePath; - - if (typeof isPage === 'function' && isPage(filePath)) { - // 生成 AST - var ast = parser.parse(source, { - sourceType: 'module', - plugins: ['jsx', 'typescript', 'classProperties'] - }); // 如果有导入申明,则默认表示已手动导入了组件 - - var insert = false; // 保存所有顶层的声明 - - var declarations = new Map(); - traverse(ast, { - // 查找是否有导入 - ImportDeclaration: function ImportDeclaration(path) { - if (path.node.source.value === importPath) { - insert = true; - } - }, - // 收集页面文件里的所有申明 - // 类组件 - ClassDeclaration: function ClassDeclaration(path) { - // 如果不是顶层的申明,则直接返回 - if (path.parent.type !== 'Program') return; - var type = path.node.type; - var name = path.node.id.name; - declarations.set(name, type); - }, - // 函数申明 - FunctionDeclaration: function FunctionDeclaration(path) { - var _path$node$id; - - // 如果不是顶层的申明,则直接返回 - if (path.parent.type !== 'Program') return; - var type = path.node.type; - var name = (_path$node$id = path.node.id) == null ? void 0 : _path$node$id.name; - if (!name) return; - declarations.set(name, type); - }, - // 表达式申明 - VariableDeclaration: function VariableDeclaration(path) { - // 如果不是顶层的申明,则直接返回 - if (path.parent.type !== 'Program') return; - path.node.declarations.forEach(function (declaration) { - var _declaration$init, _declaration$init3, _declaration$init4; - - // const a = () => {} - if (((_declaration$init = declaration.init) == null ? void 0 : _declaration$init.type) === 'ArrowFunctionExpression') { - var _declaration$init2, _declaration$id; - - var type = (_declaration$init2 = declaration.init) == null ? void 0 : _declaration$init2.type; - var name = (_declaration$id = declaration.id) == null ? void 0 : _declaration$id.name; - declarations.set(name, type); - } // const a = function(){} - - - if (((_declaration$init3 = declaration.init) == null ? void 0 : _declaration$init3.type) === 'FunctionExpression') { - var _type = declaration.init.type; - var _name = declaration.id.name; - declarations.set(_name, _type); - } // const a = class {} - - - if (((_declaration$init4 = declaration.init) == null ? void 0 : _declaration$init4.type) === 'ClassExpression') { - var _type2 = declaration.init.type; - var _name2 = declaration.id.name; - declarations.set(_name2, _type2); - } - }); - } - }); - - if (!insert) { - // 记录组件插入状态 - var state = { - importedDeclaration: false, - importedComponent: false - }; - traverse(ast, { - // 添加申明 - ImportDeclaration: function ImportDeclaration(path) { - if (!state.importedDeclaration) { - state.importedDeclaration = true; - path.insertBefore(utils.importDeclaration([utils.importDefaultSpecifier(utils.identifier('' + componentName))], utils.stringLiteral('' + importPath))); - } - }, - // 默认导出的为页面组件 - ExportDefaultDeclaration: function ExportDefaultDeclaration(path) { - // 如果默认导出的是函数 - if (path.node.declaration.type === 'FunctionDeclaration') { - var mainFnBody = path.node.declaration.body.body; - var length = mainFnBody.length; - var last = mainFnBody[length - 1]; - insertComponent(last, '' + componentName, state); - } // 默认导出箭头函数 - - - if (path.node.declaration.type === 'ArrowFunctionExpression') { - // export default () => { return } - if (path.node.declaration.body.type === 'BlockStatement') { - var _mainFnBody = path.node.declaration.body.body; - var _length = _mainFnBody.length; - var _last = _mainFnBody[_length - 1]; - insertComponent(_last, '' + componentName, state); - } else { - // export default () => - insertComponent(path.node.declaration.body, '' + componentName, state); - } - } // 默认导出类 - - - if (path.node.declaration.type === 'ClassDeclaration') { - traverse(path.node, { - ClassMethod: function ClassMethod(path) { - if (path.node.key.name === 'render') { - var body = path.node.body.body || []; - var _last2 = body[body.length - 1]; - insertComponent(_last2, '' + componentName, state); - return; - } - } - }, path.scope, path); - } // 如果默认导出的是一个申明 - - - if (path.node.declaration.type === "Identifier") { - var name = path.node.declaration.name; - var componentType = declarations.get(name); - traverse(path.parent, { - FunctionDeclaration: function FunctionDeclaration(path) { - var _path$node$id2, _path$node, _path$node$body; - - if (((_path$node$id2 = path.node.id) == null ? void 0 : _path$node$id2.name) !== name) return; - var mainFnBody = (_path$node = path.node) == null ? void 0 : (_path$node$body = _path$node.body) == null ? void 0 : _path$node$body.body; - var length = mainFnBody.length; - var last = mainFnBody[length - 1]; - insertComponent(last, '' + componentName, state); - }, - ClassDeclaration: function ClassDeclaration(path) { - if (path.node.id.name !== name) return; - traverse(path.node, { - ClassMethod: function ClassMethod(path) { - var _path$node$key; - - if (((_path$node$key = path.node.key) == null ? void 0 : _path$node$key.name) !== 'render') return; - var body = path.node.body.body || []; - var last = body[body.length - 1]; - insertComponent(last, '' + componentName, state); - } - }, path.scope, path); - }, - VariableDeclarator: function VariableDeclarator(path) { - if (path.node.id.type !== 'Identifier') return; - if (path.node.id.name !== name) return; - if (!path.node.init) return; - if (path.node.init.type !== componentType) return; - - if (path.node.init.type === 'FunctionExpression') { - var _mainFnBody2 = path.node.init.body.body; - var _length2 = _mainFnBody2.length; - var _last3 = _mainFnBody2[_length2 - 1]; - insertComponent(_last3, '' + componentName, state); - } - - if (path.node.init.type === 'ClassExpression') { - traverse(path.node, { - ClassMethod: function ClassMethod(path) { - if (path.node.key.name !== 'render') return; - var body = path.node.body.body || []; - var last = body[body.length - 1]; - insertComponent(last, '' + componentName, state); - } - }, path.scope, path); - } - - if (path.node.init.type === 'ArrowFunctionExpression') { - // const A = () => {} - // export default A - if (path.node.init.body.type == 'BlockStatement') { - var _mainFnBody3 = path.node.init.body.body; - var _length3 = _mainFnBody3.length; - var _last4 = _mainFnBody3[_length3 - 1]; - insertComponent(_last4, '' + componentName, state); - } else { - // const A = () =>
- // export default A - insertComponent(path.node.init.body, '' + componentName, state); - } - } - } - }); - } - } - }); - - if (!state.importedComponent) { - webpackEnv.emitWarning("\u9875\u9762: " + filePath + " \u6CE8\u5165\u7EC4\u4EF6\u5931\u8D25\uFF0C\u5EFA\u8BAE\u624B\u52A8\u5F15\u5165\u7EC4\u4EF6\u3002\u7EC4\u4EF6\u6CE8\u5165\u9650\u5236\u8BF7\u67E5\u9605: https://github.com/xdoer/taro-inject-component-loader"); - } - - if (!state.importedDeclaration) { - webpackEnv.emitWarning("\u9875\u9762: " + filePath + " \u6CE8\u5165\u5BFC\u5165\u7533\u660E\u5931\u8D25\uFF0C\u5EFA\u8BAE\u624B\u52A8\u5F15\u5165\u7EC4\u4EF6\u3002\u7EC4\u4EF6\u6CE8\u5165\u9650\u5236\u8BF7\u67E5\u9605: https://github.com/xdoer/taro-inject-component-loader"); - } - - source = generate(ast).code; - } - } - - return source; -} - -function createElement(name) { - var reactIdentifier = utils.identifier('React'); - var createElementIdentifier = utils.identifier('createElement'); - var callee = utils.memberExpression(reactIdentifier, createElementIdentifier); - return utils.callExpression(callee, [utils.identifier(name)]); -} - -function createJSX(name) { - return utils.jSXElement(utils.jSXOpeningElement(utils.jsxIdentifier('' + name), [], true), null, [], true); -} - -function insertComponent(node, componentName, state) { - if ((node == null ? void 0 : node.type) === 'ReturnStatement') { - var _node$argument, _node$argument$callee, _node$argument$callee2, _node$argument2; - - // createElement - if (((_node$argument = node.argument) == null ? void 0 : (_node$argument$callee = _node$argument.callee) == null ? void 0 : (_node$argument$callee2 = _node$argument$callee.property) == null ? void 0 : _node$argument$callee2.name) === 'createElement' && !state.importedComponent) { - state.importedComponent = true; - var reactCreateArguments = node.argument.arguments; - reactCreateArguments.push(createElement(componentName)); - } // JSX - - - if (((_node$argument2 = node.argument) == null ? void 0 : _node$argument2.type) === 'JSXElement' && !state.importedComponent) { - state.importedComponent = true; - node.argument.children.push(createJSX(componentName)); - } - } - - if (node.type === 'JSXElement' && !state.importedComponent) { - state.importedComponent = true; - node.children.push(createJSX(componentName)); - } -} - -function defaultJudgePage(filePath) { - // 兼容 windows 路径 - var formatFilePath = filePath.replace(/\\/g, '/'); - return /(package-.+\/)?pages\/[A-Za-z0-9-]+\/index\.[tj]sx$/.test(formatFilePath); -} - -exports.default = index; -//# sourceMappingURL=taro-inject-component-loader.cjs.development.js.map diff --git a/loaders/injectComponent/taro-inject-component-loader.cjs.development.js.map b/loaders/injectComponent/taro-inject-component-loader.cjs.development.js.map deleted file mode 100644 index b9f8994..0000000 --- a/loaders/injectComponent/taro-inject-component-loader.cjs.development.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"taro-inject-component-loader.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import generate from '@babel/generator'\r\nimport traverse from '@babel/traverse'\r\nimport utils from '@babel/types'\r\nimport { parse } from '@babel/parser'\r\nimport { getOptions } from 'loader-utils'\r\nimport { validate } from 'schema-utils'\r\n\r\nconst schema = {\r\n type: 'object',\r\n properties: {\r\n importPath: {\r\n type: 'string',\r\n },\r\n isPage: {\r\n instanceof: 'Function',\r\n },\r\n componentName: {\r\n type: 'string',\r\n },\r\n },\r\n additionalProperties: false,\r\n}\r\n\r\nexport default function (source: string) {\r\n // @ts-ignore\r\n const webpackEnv = this\r\n\r\n const options = getOptions(webpackEnv)\r\n\r\n validate(schema as any, options, { name: 'taro-inject-component-loader' })\r\n\r\n const { importPath = '', componentName = 'WebpackInjected', isPage = defaultJudgePage } = options || {}\r\n\r\n // 获取原始文件地址\r\n const filePath = webpackEnv.resourcePath\r\n\r\n if (typeof isPage === 'function' && isPage(filePath)) {\r\n // 生成 AST\r\n const ast: any = parse(source, {\r\n sourceType: 'module',\r\n plugins: ['jsx', 'typescript', 'classProperties'],\r\n })\r\n\r\n // 如果有导入申明,则默认表示已手动导入了组件\r\n let insert = false\r\n\r\n // 保存所有顶层的声明\r\n const declarations = new Map()\r\n\r\n traverse(ast, {\r\n // 查找是否有导入\r\n ImportDeclaration(path) {\r\n if (path.node.source.value === importPath) {\r\n insert = true\r\n }\r\n },\r\n\r\n // 收集页面文件里的所有申明\r\n // 类组件\r\n ClassDeclaration(path) {\r\n // 如果不是顶层的申明,则直接返回\r\n if (path.parent.type !== 'Program') return\r\n\r\n const type = path.node.type\r\n const name = path.node.id.name\r\n declarations.set(name, type)\r\n },\r\n\r\n // 函数申明\r\n FunctionDeclaration(path) {\r\n // 如果不是顶层的申明,则直接返回\r\n if (path.parent.type !== 'Program') return\r\n\r\n const type = path.node.type\r\n const name = path.node.id?.name\r\n if (!name) return\r\n\r\n declarations.set(name, type)\r\n },\r\n\r\n // 表达式申明\r\n VariableDeclaration(path) {\r\n // 如果不是顶层的申明,则直接返回\r\n if (path.parent.type !== 'Program') return\r\n\r\n path.node.declarations.forEach((declaration: any) => {\r\n\r\n // const a = () => {}\r\n if (declaration.init?.type === 'ArrowFunctionExpression') {\r\n const type = declaration.init?.type\r\n const name = declaration.id?.name\r\n declarations.set(name, type)\r\n }\r\n\r\n // const a = function(){}\r\n if (declaration.init?.type === 'FunctionExpression') {\r\n const type = declaration.init.type\r\n const name = declaration.id.name\r\n declarations.set(name, type)\r\n }\r\n\r\n // const a = class {}\r\n if (declaration.init?.type === 'ClassExpression') {\r\n const type = declaration.init.type\r\n const name = declaration.id.name\r\n declarations.set(name, type)\r\n }\r\n })\r\n },\r\n })\r\n\r\n if (!insert) {\r\n // 记录组件插入状态\r\n const state = {\r\n importedDeclaration: false,\r\n importedComponent: false,\r\n }\r\n\r\n traverse(ast, {\r\n // 添加申明\r\n ImportDeclaration(path) {\r\n if (!state.importedDeclaration) {\r\n state.importedDeclaration = true\r\n path.insertBefore(\r\n utils.importDeclaration(\r\n [\r\n utils.importDefaultSpecifier(utils.identifier('' + componentName)),\r\n ],\r\n utils.stringLiteral('' + importPath),\r\n ),\r\n )\r\n }\r\n },\r\n\r\n // 默认导出的为页面组件\r\n ExportDefaultDeclaration(path) {\r\n\r\n // 如果默认导出的是函数\r\n if (path.node.declaration.type === 'FunctionDeclaration') {\r\n const mainFnBody = path.node.declaration.body.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n }\r\n\r\n // 默认导出箭头函数\r\n if (path.node.declaration.type === 'ArrowFunctionExpression') {\r\n // export default () => { return }\r\n if (path.node.declaration.body.type === 'BlockStatement') {\r\n const mainFnBody = path.node.declaration.body.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n } else {\r\n // export default () => \r\n insertComponent(path.node.declaration.body, '' + componentName, state)\r\n }\r\n }\r\n\r\n // 默认导出类\r\n if (path.node.declaration.type === 'ClassDeclaration') {\r\n traverse(path.node, {\r\n ClassMethod(path) {\r\n if ((path.node.key as any).name === 'render') {\r\n const body = path.node.body.body || []\r\n const last = body[body.length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n return\r\n }\r\n },\r\n }, path.scope, path)\r\n }\r\n\r\n // 如果默认导出的是一个申明\r\n if (path.node.declaration.type === \"Identifier\") {\r\n const name = path.node.declaration.name\r\n const componentType = declarations.get(name)\r\n\r\n traverse(path.parent, {\r\n FunctionDeclaration(path) {\r\n if (path.node.id?.name !== name) return\r\n const mainFnBody = path.node?.body?.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n },\r\n ClassDeclaration(path) {\r\n if (path.node.id.name !== name) return\r\n traverse(path.node, {\r\n ClassMethod(path) {\r\n if ((path.node.key as any)?.name !== 'render') return\r\n const body = path.node.body.body || []\r\n const last = body[body.length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n },\r\n }, path.scope, path)\r\n },\r\n VariableDeclarator(path) {\r\n if (path.node.id.type !== 'Identifier') return\r\n if (path.node.id.name !== name) return\r\n if (!path.node.init) return\r\n\r\n if (path.node.init.type !== componentType) return\r\n\r\n if (path.node.init.type === 'FunctionExpression') {\r\n const mainFnBody = path.node.init.body.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n }\r\n\r\n if (path.node.init.type === 'ClassExpression') {\r\n traverse(path.node, {\r\n ClassMethod(path) {\r\n if ((path.node.key as any).name !== 'render') return\r\n const body = path.node.body.body || []\r\n const last = body[body.length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n },\r\n }, path.scope, path)\r\n }\r\n\r\n if (path.node.init.type === 'ArrowFunctionExpression') {\r\n // const A = () => {}\r\n // export default A\r\n if (path.node.init.body.type == 'BlockStatement') {\r\n const mainFnBody = path.node.init.body.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n } else {\r\n // const A = () =>
\r\n // export default A\r\n insertComponent(path.node.init.body, '' + componentName, state)\r\n }\r\n }\r\n }\r\n })\r\n }\r\n },\r\n })\r\n\r\n if (!state.importedComponent) {\r\n webpackEnv.emitWarning(`页面: ${filePath} 注入组件失败,建议手动引入组件。组件注入限制请查阅: https://github.com/xdoer/taro-inject-component-loader`)\r\n\r\n }\r\n if (!state.importedDeclaration) {\r\n webpackEnv.emitWarning(`页面: ${filePath} 注入导入申明失败,建议手动引入组件。组件注入限制请查阅: https://github.com/xdoer/taro-inject-component-loader`)\r\n }\r\n\r\n source = generate(ast).code\r\n }\r\n }\r\n\r\n return source\r\n}\r\n\r\n\r\nfunction createElement(name: string) {\r\n const reactIdentifier = utils.identifier('React')\r\n const createElementIdentifier = utils.identifier('createElement')\r\n const callee = utils.memberExpression(reactIdentifier, createElementIdentifier)\r\n return utils.callExpression(callee, [utils.identifier(name)])\r\n}\r\n\r\nfunction createJSX(name: string) {\r\n return utils.jSXElement(\r\n utils.jSXOpeningElement(utils.jsxIdentifier('' + name), [], true),\r\n null,\r\n [],\r\n true,\r\n )\r\n}\r\n\r\nfunction insertComponent(node: any, componentName: string, state: any) {\r\n if (node?.type === 'ReturnStatement') {\r\n // createElement\r\n if (node.argument?.callee?.property?.name === 'createElement' && !state.importedComponent) {\r\n state.importedComponent = true\r\n const reactCreateArguments = node.argument.arguments\r\n reactCreateArguments.push(createElement(componentName))\r\n }\r\n // JSX\r\n if (node.argument?.type === 'JSXElement' && !state.importedComponent) {\r\n state.importedComponent = true\r\n node.argument.children.push(createJSX(componentName))\r\n }\r\n }\r\n if (node.type === 'JSXElement' && !state.importedComponent) {\r\n state.importedComponent = true\r\n node.children.push(createJSX(componentName))\r\n }\r\n}\r\n\r\nfunction defaultJudgePage(filePath: string) {\r\n // 兼容 windows 路径\r\n const formatFilePath = filePath.replace(/\\\\/g, '/')\r\n return /(package-.+\\/)?pages\\/[A-Za-z0-9-]+\\/index\\.[tj]sx$/.test(formatFilePath)\r\n}\r\n"],"names":["schema","type","properties","importPath","isPage","componentName","additionalProperties","source","webpackEnv","options","getOptions","validate","name","defaultJudgePage","filePath","resourcePath","ast","parse","sourceType","plugins","insert","declarations","Map","traverse","ImportDeclaration","path","node","value","ClassDeclaration","parent","id","set","FunctionDeclaration","VariableDeclaration","forEach","declaration","init","state","importedDeclaration","importedComponent","insertBefore","utils","importDeclaration","importDefaultSpecifier","identifier","stringLiteral","ExportDefaultDeclaration","mainFnBody","body","length","last","insertComponent","ClassMethod","key","scope","componentType","get","VariableDeclarator","emitWarning","generate","code","createElement","reactIdentifier","createElementIdentifier","callee","memberExpression","callExpression","createJSX","jSXElement","jSXOpeningElement","jsxIdentifier","argument","property","reactCreateArguments","arguments","push","children","formatFilePath","replace","test"],"mappings":";;;;;;;;;;;;;AAOA,IAAMA,MAAM,GAAG;AACbC,EAAAA,IAAI,EAAE,QADO;AAEbC,EAAAA,UAAU,EAAE;AACVC,IAAAA,UAAU,EAAE;AACVF,MAAAA,IAAI,EAAE;AADI,KADF;AAIVG,IAAAA,MAAM,EAAE;AACN,oBAAY;AADN,KAJE;AAOVC,IAAAA,aAAa,EAAE;AACbJ,MAAAA,IAAI,EAAE;AADO;AAPL,GAFC;AAabK,EAAAA,oBAAoB,EAAE;AAbT,CAAf;gBAgByBC;AACvB;AACA,MAAMC,UAAU,GAAG,IAAnB;AAEA,MAAMC,OAAO,GAAGC,sBAAU,CAACF,UAAD,CAA1B;AAEAG,EAAAA,oBAAQ,CAACX,MAAD,EAAgBS,OAAhB,EAAyB;AAAEG,IAAAA,IAAI,EAAE;AAAR,GAAzB,CAAR;;AAEA,aAA0FH,OAAO,IAAI,EAArG;AAAA,6BAAQN,UAAR;AAAA,MAAQA,UAAR,gCAAqB,EAArB;AAAA,gCAAyBE,aAAzB;AAAA,MAAyBA,aAAzB,mCAAyC,iBAAzC;AAAA,yBAA4DD,MAA5D;AAAA,MAA4DA,MAA5D,4BAAqES,gBAArE;;;AAGA,MAAMC,QAAQ,GAAGN,UAAU,CAACO,YAA5B;;AAEA,MAAI,OAAOX,MAAP,KAAkB,UAAlB,IAAgCA,MAAM,CAACU,QAAD,CAA1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AAvB;AACA,SAAO,sDAAsDC,IAAtD,CAA2DF,cAA3D,CAAP;AACD;;;;"} \ No newline at end of file diff --git a/loaders/injectComponent/taro-inject-component-loader.cjs.production.min.js b/loaders/injectComponent/taro-inject-component-loader.cjs.production.min.js deleted file mode 100644 index 80ad56e..0000000 --- a/loaders/injectComponent/taro-inject-component-loader.cjs.production.min.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=e(require("@babel/generator")),t=e(require("@babel/traverse")),o=e(require("@babel/types")),i=require("@babel/parser"),r=require("loader-utils"),a=require("schema-utils"),d={type:"object",properties:{importPath:{type:"string"},isPage:{instanceof:"Function"},componentName:{type:"string"}},additionalProperties:!1};function l(e){return o.jSXElement(o.jSXOpeningElement(o.jsxIdentifier(""+e),[],!0),null,[],!0)}function p(e,n,t){var i,r,a,d,p,c,s,u;"ReturnStatement"===(null==e?void 0:e.type)&&("createElement"!==(null==(i=e.argument)||null==(r=i.callee)||null==(a=r.property)?void 0:a.name)||t.importedComponent||(t.importedComponent=!0,e.argument.arguments.push((p=n,c=o.identifier("React"),s=o.identifier("createElement"),u=o.memberExpression(c,s),o.callExpression(u,[o.identifier(p)])))),"JSXElement"!==(null==(d=e.argument)?void 0:d.type)||t.importedComponent||(t.importedComponent=!0,e.argument.children.push(l(n)))),"JSXElement"!==e.type||t.importedComponent||(t.importedComponent=!0,e.children.push(l(n)))}function c(e){var n=e.replace(/\\/g,"/");return/(package-.+\/)?pages\/[A-Za-z0-9-]+\/index\.[tj]sx$/.test(n)}exports.default=function(e){var l=r.getOptions(this);a.validate(d,l,{name:"taro-inject-component-loader"});var s=l||{},u=s.importPath,m=void 0===u?"":u,y=s.componentName,f=void 0===y?"WebpackInjected":y,v=s.isPage,b=void 0===v?c:v,g=this.resourcePath;if("function"==typeof b&&b(g)){var h=i.parse(e,{sourceType:"module",plugins:["jsx","typescript","classProperties"]}),x=!1,D=new Map;if(t(h,{ImportDeclaration:function(e){e.node.source.value===m&&(x=!0)},ClassDeclaration:function(e){"Program"===e.parent.type&&D.set(e.node.id.name,e.node.type)},FunctionDeclaration:function(e){var n;if("Program"===e.parent.type){var t=null==(n=e.node.id)?void 0:n.name;t&&D.set(t,e.node.type)}},VariableDeclaration:function(e){"Program"===e.parent.type&&e.node.declarations.forEach((function(e){var n,t,o;if("ArrowFunctionExpression"===(null==(n=e.init)?void 0:n.type)){var i,r,a=null==(i=e.init)?void 0:i.type,d=null==(r=e.id)?void 0:r.name;D.set(d,a)}"FunctionExpression"===(null==(t=e.init)?void 0:t.type)&&D.set(e.id.name,e.init.type),"ClassExpression"===(null==(o=e.init)?void 0:o.type)&&D.set(e.id.name,e.init.type)}))}}),!x){var E={importedDeclaration:!1,importedComponent:!1};t(h,{ImportDeclaration:function(e){E.importedDeclaration||(E.importedDeclaration=!0,e.insertBefore(o.importDeclaration([o.importDefaultSpecifier(o.identifier(""+f))],o.stringLiteral(""+m))))},ExportDefaultDeclaration:function(e){if("FunctionDeclaration"===e.node.declaration.type){var n=e.node.declaration.body.body;p(n[n.length-1],""+f,E)}if("ArrowFunctionExpression"===e.node.declaration.type)if("BlockStatement"===e.node.declaration.body.type){var o=e.node.declaration.body.body;p(o[o.length-1],""+f,E)}else p(e.node.declaration.body,""+f,E);if("ClassDeclaration"===e.node.declaration.type&&t(e.node,{ClassMethod:function(e){if("render"!==e.node.key.name);else{var n=e.node.body.body||[];p(n[n.length-1],""+f,E)}}},e.scope,e),"Identifier"===e.node.declaration.type){var i=e.node.declaration.name,r=D.get(i);t(e.parent,{FunctionDeclaration:function(e){var n,t,o;if((null==(n=e.node.id)?void 0:n.name)===i){var r=null==(t=e.node)||null==(o=t.body)?void 0:o.body;p(r[r.length-1],""+f,E)}},ClassDeclaration:function(e){e.node.id.name===i&&t(e.node,{ClassMethod:function(e){var n;if("render"===(null==(n=e.node.key)?void 0:n.name)){var t=e.node.body.body||[];p(t[t.length-1],""+f,E)}}},e.scope,e)},VariableDeclarator:function(e){if("Identifier"===e.node.id.type&&e.node.id.name===i&&e.node.init&&e.node.init.type===r){if("FunctionExpression"===e.node.init.type){var n=e.node.init.body.body;p(n[n.length-1],""+f,E)}if("ClassExpression"===e.node.init.type&&t(e.node,{ClassMethod:function(e){if("render"===e.node.key.name){var n=e.node.body.body||[];p(n[n.length-1],""+f,E)}}},e.scope,e),"ArrowFunctionExpression"===e.node.init.type)if("BlockStatement"==e.node.init.body.type){var o=e.node.init.body.body;p(o[o.length-1],""+f,E)}else p(e.node.init.body,""+f,E)}}})}}}),E.importedComponent||this.emitWarning("页面: "+g+" 注入组件失败,建议手动引入组件。组件注入限制请查阅: https://github.com/xdoer/taro-inject-component-loader"),E.importedDeclaration||this.emitWarning("页面: "+g+" 注入导入申明失败,建议手动引入组件。组件注入限制请查阅: https://github.com/xdoer/taro-inject-component-loader"),e=n(h).code}}return e}; -//# sourceMappingURL=taro-inject-component-loader.cjs.production.min.js.map diff --git a/loaders/injectComponent/taro-inject-component-loader.cjs.production.min.js.map b/loaders/injectComponent/taro-inject-component-loader.cjs.production.min.js.map deleted file mode 100644 index f4161fb..0000000 --- a/loaders/injectComponent/taro-inject-component-loader.cjs.production.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"taro-inject-component-loader.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import generate from '@babel/generator'\r\nimport traverse from '@babel/traverse'\r\nimport utils from '@babel/types'\r\nimport { parse } from '@babel/parser'\r\nimport { getOptions } from 'loader-utils'\r\nimport { validate } from 'schema-utils'\r\n\r\nconst schema = {\r\n type: 'object',\r\n properties: {\r\n importPath: {\r\n type: 'string',\r\n },\r\n isPage: {\r\n instanceof: 'Function',\r\n },\r\n componentName: {\r\n type: 'string',\r\n },\r\n },\r\n additionalProperties: false,\r\n}\r\n\r\nexport default function (source: string) {\r\n // @ts-ignore\r\n const webpackEnv = this\r\n\r\n const options = getOptions(webpackEnv)\r\n\r\n validate(schema as any, options, { name: 'taro-inject-component-loader' })\r\n\r\n const { importPath = '', componentName = 'WebpackInjected', isPage = defaultJudgePage } = options || {}\r\n\r\n // 获取原始文件地址\r\n const filePath = webpackEnv.resourcePath\r\n\r\n if (typeof isPage === 'function' && isPage(filePath)) {\r\n // 生成 AST\r\n const ast: any = parse(source, {\r\n sourceType: 'module',\r\n plugins: ['jsx', 'typescript', 'classProperties'],\r\n })\r\n\r\n // 如果有导入申明,则默认表示已手动导入了组件\r\n let insert = false\r\n\r\n // 保存所有顶层的声明\r\n const declarations = new Map()\r\n\r\n traverse(ast, {\r\n // 查找是否有导入\r\n ImportDeclaration(path) {\r\n if (path.node.source.value === importPath) {\r\n insert = true\r\n }\r\n },\r\n\r\n // 收集页面文件里的所有申明\r\n // 类组件\r\n ClassDeclaration(path) {\r\n // 如果不是顶层的申明,则直接返回\r\n if (path.parent.type !== 'Program') return\r\n\r\n const type = path.node.type\r\n const name = path.node.id.name\r\n declarations.set(name, type)\r\n },\r\n\r\n // 函数申明\r\n FunctionDeclaration(path) {\r\n // 如果不是顶层的申明,则直接返回\r\n if (path.parent.type !== 'Program') return\r\n\r\n const type = path.node.type\r\n const name = path.node.id?.name\r\n if (!name) return\r\n\r\n declarations.set(name, type)\r\n },\r\n\r\n // 表达式申明\r\n VariableDeclaration(path) {\r\n // 如果不是顶层的申明,则直接返回\r\n if (path.parent.type !== 'Program') return\r\n\r\n path.node.declarations.forEach((declaration: any) => {\r\n\r\n // const a = () => {}\r\n if (declaration.init?.type === 'ArrowFunctionExpression') {\r\n const type = declaration.init?.type\r\n const name = declaration.id?.name\r\n declarations.set(name, type)\r\n }\r\n\r\n // const a = function(){}\r\n if (declaration.init?.type === 'FunctionExpression') {\r\n const type = declaration.init.type\r\n const name = declaration.id.name\r\n declarations.set(name, type)\r\n }\r\n\r\n // const a = class {}\r\n if (declaration.init?.type === 'ClassExpression') {\r\n const type = declaration.init.type\r\n const name = declaration.id.name\r\n declarations.set(name, type)\r\n }\r\n })\r\n },\r\n })\r\n\r\n if (!insert) {\r\n // 记录组件插入状态\r\n const state = {\r\n importedDeclaration: false,\r\n importedComponent: false,\r\n }\r\n\r\n traverse(ast, {\r\n // 添加申明\r\n ImportDeclaration(path) {\r\n if (!state.importedDeclaration) {\r\n state.importedDeclaration = true\r\n path.insertBefore(\r\n utils.importDeclaration(\r\n [\r\n utils.importDefaultSpecifier(utils.identifier('' + componentName)),\r\n ],\r\n utils.stringLiteral('' + importPath),\r\n ),\r\n )\r\n }\r\n },\r\n\r\n // 默认导出的为页面组件\r\n ExportDefaultDeclaration(path) {\r\n\r\n // 如果默认导出的是函数\r\n if (path.node.declaration.type === 'FunctionDeclaration') {\r\n const mainFnBody = path.node.declaration.body.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n }\r\n\r\n // 默认导出箭头函数\r\n if (path.node.declaration.type === 'ArrowFunctionExpression') {\r\n // export default () => { return }\r\n if (path.node.declaration.body.type === 'BlockStatement') {\r\n const mainFnBody = path.node.declaration.body.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n } else {\r\n // export default () => \r\n insertComponent(path.node.declaration.body, '' + componentName, state)\r\n }\r\n }\r\n\r\n // 默认导出类\r\n if (path.node.declaration.type === 'ClassDeclaration') {\r\n traverse(path.node, {\r\n ClassMethod(path) {\r\n if ((path.node.key as any).name === 'render') {\r\n const body = path.node.body.body || []\r\n const last = body[body.length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n return\r\n }\r\n },\r\n }, path.scope, path)\r\n }\r\n\r\n // 如果默认导出的是一个申明\r\n if (path.node.declaration.type === \"Identifier\") {\r\n const name = path.node.declaration.name\r\n const componentType = declarations.get(name)\r\n\r\n traverse(path.parent, {\r\n FunctionDeclaration(path) {\r\n if (path.node.id?.name !== name) return\r\n const mainFnBody = path.node?.body?.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n },\r\n ClassDeclaration(path) {\r\n if (path.node.id.name !== name) return\r\n traverse(path.node, {\r\n ClassMethod(path) {\r\n if ((path.node.key as any)?.name !== 'render') return\r\n const body = path.node.body.body || []\r\n const last = body[body.length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n },\r\n }, path.scope, path)\r\n },\r\n VariableDeclarator(path) {\r\n if (path.node.id.type !== 'Identifier') return\r\n if (path.node.id.name !== name) return\r\n if (!path.node.init) return\r\n\r\n if (path.node.init.type !== componentType) return\r\n\r\n if (path.node.init.type === 'FunctionExpression') {\r\n const mainFnBody = path.node.init.body.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n }\r\n\r\n if (path.node.init.type === 'ClassExpression') {\r\n traverse(path.node, {\r\n ClassMethod(path) {\r\n if ((path.node.key as any).name !== 'render') return\r\n const body = path.node.body.body || []\r\n const last = body[body.length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n },\r\n }, path.scope, path)\r\n }\r\n\r\n if (path.node.init.type === 'ArrowFunctionExpression') {\r\n // const A = () => {}\r\n // export default A\r\n if (path.node.init.body.type == 'BlockStatement') {\r\n const mainFnBody = path.node.init.body.body\r\n const length = mainFnBody.length\r\n const last = mainFnBody[length - 1]\r\n insertComponent(last, '' + componentName, state)\r\n } else {\r\n // const A = () =>
\r\n // export default A\r\n insertComponent(path.node.init.body, '' + componentName, state)\r\n }\r\n }\r\n }\r\n })\r\n }\r\n },\r\n })\r\n\r\n if (!state.importedComponent) {\r\n webpackEnv.emitWarning(`页面: ${filePath} 注入组件失败,建议手动引入组件。组件注入限制请查阅: https://github.com/xdoer/taro-inject-component-loader`)\r\n\r\n }\r\n if (!state.importedDeclaration) {\r\n webpackEnv.emitWarning(`页面: ${filePath} 注入导入申明失败,建议手动引入组件。组件注入限制请查阅: https://github.com/xdoer/taro-inject-component-loader`)\r\n }\r\n\r\n source = generate(ast).code\r\n }\r\n }\r\n\r\n return source\r\n}\r\n\r\n\r\nfunction createElement(name: string) {\r\n const reactIdentifier = utils.identifier('React')\r\n const createElementIdentifier = utils.identifier('createElement')\r\n const callee = utils.memberExpression(reactIdentifier, createElementIdentifier)\r\n return utils.callExpression(callee, [utils.identifier(name)])\r\n}\r\n\r\nfunction createJSX(name: string) {\r\n return utils.jSXElement(\r\n utils.jSXOpeningElement(utils.jsxIdentifier('' + name), [], true),\r\n null,\r\n [],\r\n true,\r\n )\r\n}\r\n\r\nfunction insertComponent(node: any, componentName: string, state: any) {\r\n if (node?.type === 'ReturnStatement') {\r\n // createElement\r\n if (node.argument?.callee?.property?.name === 'createElement' && !state.importedComponent) {\r\n state.importedComponent = true\r\n const reactCreateArguments = node.argument.arguments\r\n reactCreateArguments.push(createElement(componentName))\r\n }\r\n // JSX\r\n if (node.argument?.type === 'JSXElement' && !state.importedComponent) {\r\n state.importedComponent = true\r\n node.argument.children.push(createJSX(componentName))\r\n }\r\n }\r\n if (node.type === 'JSXElement' && !state.importedComponent) {\r\n state.importedComponent = true\r\n node.children.push(createJSX(componentName))\r\n }\r\n}\r\n\r\nfunction defaultJudgePage(filePath: string) {\r\n // 兼容 windows 路径\r\n const formatFilePath = filePath.replace(/\\\\/g, '/')\r\n return /(package-.+\\/)?pages\\/[A-Za-z0-9-]+\\/index\\.[tj]sx$/.test(formatFilePath)\r\n}\r\n"],"names":["schema","type","properties","importPath","isPage","componentName","additionalProperties","createJSX","name","utils","jSXElement","jSXOpeningElement","jsxIdentifier","insertComponent","node","state","reactIdentifier","createElementIdentifier","callee","argument","property","importedComponent","arguments","push","identifier","memberExpression","callExpression","children","defaultJudgePage","filePath","formatFilePath","replace","test","source","options","getOptions","this","validate","resourcePath","ast","parse","sourceType","plugins","insert","declarations","Map","traverse","ImportDeclaration","path","value","ClassDeclaration","parent","set","id","FunctionDeclaration","_path$node$id","VariableDeclaration","forEach","declaration","init","_declaration$init2","_declaration$id","importedDeclaration","insertBefore","importDeclaration","importDefaultSpecifier","stringLiteral","ExportDefaultDeclaration","mainFnBody","body","length","ClassMethod","key","scope","componentType","get","_path$node","_path$node$body","VariableDeclarator","emitWarning","generate","code"],"mappings":"2TAOMA,EAAS,CACbC,KAAM,SACNC,WAAY,CACVC,WAAY,CACVF,KAAM,UAERG,OAAQ,YACM,YAEdC,cAAe,CACbJ,KAAM,WAGVK,sBAAsB,GAqPxB,SAASC,EAAUC,UACVC,EAAMC,WACXD,EAAME,kBAAkBF,EAAMG,cAAc,GAAKJ,GAAO,IAAI,GAC5D,KACA,IACA,GAIJ,SAASK,EAAgBC,EAAWT,EAAuBU,eAhBpCP,EACfQ,EACAC,EACAC,EAca,2BAAfJ,SAAAA,EAAMb,QAEsC,4BAA1Ca,EAAKK,sBAAUD,oBAAQE,mBAAUZ,OAA6BO,EAAMM,oBACtEN,EAAMM,mBAAoB,EACGP,EAAKK,SAASG,UACtBC,MAtBJf,EAsBuBH,EArBtCW,EAAkBP,EAAMe,WAAW,SACnCP,EAA0BR,EAAMe,WAAW,iBAC3CN,EAAST,EAAMgB,iBAAiBT,EAAiBC,GAChDR,EAAMiB,eAAeR,EAAQ,CAACT,EAAMe,WAAWhB,QAqBxB,yBAAxBM,EAAKK,mBAAUlB,OAA0Bc,EAAMM,oBACjDN,EAAMM,mBAAoB,EAC1BP,EAAKK,SAASQ,SAASJ,KAAKhB,EAAUF,MAGxB,eAAdS,EAAKb,MAA0Bc,EAAMM,oBACvCN,EAAMM,mBAAoB,EAC1BP,EAAKa,SAASJ,KAAKhB,EAAUF,KAIjC,SAASuB,EAAiBC,OAElBC,EAAiBD,EAASE,QAAQ,MAAO,WACxC,sDAAsDC,KAAKF,4BAlR3CG,OAIjBC,EAAUC,aAFGC,MAInBC,WAASrC,EAAekC,EAAS,CAAE1B,KAAM,uCAEiD0B,GAAW,OAA7F/B,WAAAA,aAAa,SAAIE,cAAAA,aAAgB,wBAAmBD,OAAAA,aAASwB,IAG/DC,EATaO,KASSE,gBAEN,mB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E,EAAeU,MAE3CiC,EAAKyB,MAAOzB,IAEjB8B,4BAAmB9B,MACS,eAAtBA,EAAKlC,KAAKuC,GAAGpD,MACb+C,EAAKlC,KAAKuC,GAAG7C,OAASA,GACrBwC,EAAKlC,KAAK6C,MAEXX,EAAKlC,KAAK6C,KAAK1D,OAASyE,MAEA,uBAAxB1B,EAAKlC,KAAK6C,KAAK1D,KAA+B,KAC1CmE,EAAapB,EAAKlC,KAAK6C,KAAKU,KAAKA,KAGvCxD,EADauD,EADEA,EAAWE,OACO,GACX,GAAKjE,EAAeU,MAGhB,oBAAxBiC,EAAKlC,KAAK6C,KAAK1D,MACjB6C,EAASE,EAAKlC,KAAM,CAClByD,qBAAYvB,MAC0B,WAA/BA,EAAKlC,KAAK0D,IAAYhE,UACrB6D,EAAOrB,EAAKlC,KAAKuD,KAAKA,MAAQ,GAEpCxD,EADawD,EAAKA,EAAKC,OAAS,GACV,GAAKjE,EAAeU,MAE3CiC,EAAKyB,MAAOzB,GAGW,4BAAxBA,EAAKlC,KAAK6C,KAAK1D,QAGe,kBAA5B+C,EAAKlC,KAAK6C,KAAKU,KAAKpE,KAA0B,KAC1CmE,EAAapB,EAAKlC,KAAK6C,KAAKU,KAAKA,KAGvCxD,EADauD,EADEA,EAAWE,OACO,GACX,GAAKjE,EAAeU,QAI1CF,EAAgBmC,EAAKlC,KAAK6C,KAAKU,KAAM,GAAKhE,EAAeU,WASlEA,EAAMM,mBAzNIe,KA0NF2C,mBAAmBlD,uFAG3Bd,EAAM+C,qBA7NI1B,KA8NF2C,mBAAmBlD,yFAGhCI,EAAS+C,EAASzC,GAAK0C,aAIpBhD"} \ No newline at end of file diff --git a/loaders/taro-inject-component-loader/package.json b/loaders/taro-inject-component-loader/package.json deleted file mode 100644 index ba304c2..0000000 --- a/loaders/taro-inject-component-loader/package.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "version": "2.1.0", - "license": "MIT", - "main": "dist/index.js", - "typings": "dist/index.d.ts", - "files": [ - "dist" - ], - "engines": { - "node": ">=10" - }, - "homepage": "https://github.com/xdoer/taro-inject-component-loader", - "bugs": { - "url": "https://github.com/xdoer/taro-inject-component-loader/issues", - "email": "gotoanything@foxmail.com" - }, - "keywords": [ - "taro", - "react", - "loader", - "webpack", - "inject" - ], - "scripts": { - "start": "tsdx watch --format cjs", - "build": "tsdx build --format cjs", - "test": "tsdx test", - "lint": "tsdx lint", - "prepare": "tsdx build --format cjs", - "size": "size-limit", - "analyze": "size-limit --why" - }, - "husky": { - "hooks": { - "pre-commit": "tsdx lint" - } - }, - "name": "taro-inject-component-loader", - "author": "xdoer", - "module": "dist/taro-inject-component-loader.esm.js", - "size-limit": [ - { - "path": "dist/taro-inject-component-loader.cjs.production.min.js", - "limit": "10 KB" - }, - { - "path": "dist/taro-inject-component-loader.esm.js", - "limit": "10 KB" - } - ], - "peerDependencies": { - "webpack": "^4.0.0 || ^5.0.0" - }, - "dependencies": { - "loader-utils": "^2.0.0", - "schema-utils": "^3.0.0" - }, - "devDependencies": { - "@size-limit/preset-small-lib": "^4.9.1", - "@types/loader-utils": "^2.0.1", - "@types/schema-utils": "^2.4.0", - "husky": "^4.3.6", - "size-limit": "^4.9.1", - "tsdx": "^0.14.1", - "tslib": "^2.0.3", - "typescript": "^4.1.3" - } -} diff --git a/loaders/taro-inject-component-loader/src/index.ts b/loaders/taro-inject-component-loader/src/index.ts deleted file mode 100644 index 1ae5e8b..0000000 --- a/loaders/taro-inject-component-loader/src/index.ts +++ /dev/null @@ -1,295 +0,0 @@ -import generate from '@babel/generator' -import traverse from '@babel/traverse' -import utils from '@babel/types' -import { parse } from '@babel/parser' -import { getOptions } from 'loader-utils' -import { validate } from 'schema-utils' - -const schema = { - type: 'object', - properties: { - importPath: { - type: 'string', - }, - isPage: { - instanceof: 'Function', - }, - }, - additionalProperties: false, -} - -export default function (source: string) { - // @ts-ignore - const webpackEnv = this - - const options = getOptions(webpackEnv) - - validate(schema as any, options, { name: 'taro-inject-component-loader' }) - - const { importPath = '', componentName = 'WebpackInjected', isPage = defaultJudgePage } = options || {} - - // 获取原始文件地址 - const filePath = webpackEnv.resourcePath - - if (typeof isPage === 'function' && isPage(filePath)) { - // 生成 AST - const ast: any = parse(source, { - sourceType: 'module', - plugins: ['jsx', 'typescript', 'classProperties'], - }) - - // 如果有导入申明,则默认表示已手动导入了组件 - let insert = false - - // 保存所有顶层的声明 - const declarations = new Map() - - traverse(ast, { - // 查找是否有导入 - ImportDeclaration(path) { - if (path.node.source.value === importPath) { - insert = true - } - }, - - // 收集页面文件里的所有申明 - // 类组件 - ClassDeclaration(path) { - // 如果不是顶层的申明,则直接返回 - if (path.parent.type !== 'Program') return - - const type = path.node.type - const name = path.node.id.name - declarations.set(name, type) - }, - - // 函数申明 - FunctionDeclaration(path) { - // 如果不是顶层的申明,则直接返回 - if (path.parent.type !== 'Program') return - - const type = path.node.type - const name = path.node.id?.name - if (!name) return - - declarations.set(name, type) - }, - - // 表达式申明 - VariableDeclaration(path) { - // 如果不是顶层的申明,则直接返回 - if (path.parent.type !== 'Program') return - - path.node.declarations.forEach((declaration: any) => { - - // const a = () => {} - if (declaration.init?.type === 'ArrowFunctionExpression') { - const type = declaration.init?.type - const name = declaration.id?.name - declarations.set(name, type) - } - - // const a = function(){} - if (declaration.init?.type === 'FunctionExpression') { - const type = declaration.init.type - const name = declaration.id.name - declarations.set(name, type) - } - - // const a = class {} - if (declaration.init?.type === 'ClassExpression') { - const type = declaration.init.type - const name = declaration.id.name - declarations.set(name, type) - } - }) - }, - }) - - if (!insert) { - // 记录组件插入状态 - const state = { - importedDeclaration: false, - importedComponent: false, - } - - traverse(ast, { - // 添加申明 - ImportDeclaration(path) { - if (!state.importedDeclaration) { - state.importedDeclaration = true - path.insertBefore( - utils.importDeclaration( - [ - utils.importDefaultSpecifier(utils.identifier('' + componentName)), - ], - utils.stringLiteral('' + importPath), - ), - ) - } - }, - - // 默认导出的为页面组件 - ExportDefaultDeclaration(path) { - - // 如果默认导出的是函数 - if (path.node.declaration.type === 'FunctionDeclaration') { - const mainFnBody = path.node.declaration.body.body - const length = mainFnBody.length - const last = mainFnBody[length - 1] - insertComponent(last, '' + componentName, state) - } - - // 默认导出箭头函数 - if (path.node.declaration.type === 'ArrowFunctionExpression') { - // export default () => { return } - if (path.node.declaration.body.type === 'BlockStatement') { - const mainFnBody = path.node.declaration.body.body - const length = mainFnBody.length - const last = mainFnBody[length - 1] - insertComponent(last, '' + componentName, state) - } else { - // export default () => - insertComponent(path.node.declaration.body, '' + componentName, state) - } - } - - // 默认导出类 - if (path.node.declaration.type === 'ClassDeclaration') { - traverse(path.node, { - ClassMethod(path) { - if ((path.node.key as any).name === 'render') { - const body = path.node.body.body || [] - const last = body[body.length - 1] - insertComponent(last, '' + componentName, state) - return - } - }, - }, path.scope, path) - } - - // 如果默认导出的是一个申明 - if (path.node.declaration.type === "Identifier") { - const name = path.node.declaration.name - const componentType = declarations.get(name) - - traverse(path.parent, { - FunctionDeclaration(path) { - if (path.node.id?.name !== name) return - const mainFnBody = path.node?.body?.body - const length = mainFnBody.length - const last = mainFnBody[length - 1] - insertComponent(last, '' + componentName, state) - }, - ClassDeclaration(path) { - if (path.node.id.name !== name) return - traverse(path.node, { - ClassMethod(path) { - if ((path.node.key as any)?.name !== 'render') return - const body = path.node.body.body || [] - const last = body[body.length - 1] - insertComponent(last, '' + componentName, state) - }, - }, path.scope, path) - }, - VariableDeclarator(path) { - if (path.node.id.type !== 'Identifier') return - if (path.node.id.name !== name) return - if (!path.node.init) return - - if (path.node.init.type !== componentType) return - - if (path.node.init.type === 'FunctionExpression') { - const mainFnBody = path.node.init.body.body - const length = mainFnBody.length - const last = mainFnBody[length - 1] - insertComponent(last, '' + componentName, state) - } - - if (path.node.init.type === 'ClassExpression') { - traverse(path.node, { - ClassMethod(path) { - if ((path.node.key as any).name !== 'render') return - const body = path.node.body.body || [] - const last = body[body.length - 1] - insertComponent(last, '' + componentName, state) - }, - }, path.scope, path) - } - - if (path.node.init.type === 'ArrowFunctionExpression') { - // const A = () => {} - // export default A - if (path.node.init.body.type == 'BlockStatement') { - const mainFnBody = path.node.init.body.body - const length = mainFnBody.length - const last = mainFnBody[length - 1] - insertComponent(last, '' + componentName, state) - } else { - // const A = () =>
- // export default A - insertComponent(path.node.init.body, '' + componentName, state) - } - } - } - }) - } - }, - }) - - if (!state.importedComponent) { - webpackEnv.emitWarning(`页面: ${filePath} 注入组件失败,建议手动引入组件。组件注入限制请查阅: https://github.com/xdoer/taro-inject-component-loader`) - - } - if (!state.importedDeclaration) { - webpackEnv.emitWarning(`页面: ${filePath} 注入导入申明失败,建议手动引入组件。组件注入限制请查阅: https://github.com/xdoer/taro-inject-component-loader`) - } - - source = generate(ast).code - } - } - - return source -} - - -function createElement(name: string) { - const reactIdentifier = utils.identifier('React') - const createElementIdentifier = utils.identifier('createElement') - const callee = utils.memberExpression(reactIdentifier, createElementIdentifier) - return utils.callExpression(callee, [utils.identifier(name)]) -} - -function createJSX(name: string) { - return utils.jSXElement( - utils.jSXOpeningElement(utils.jsxIdentifier('' + name), [], true), - null, - [], - true, - ) -} - -function insertComponent(node: any, componentName: string, state: any) { - if (node?.type === 'ReturnStatement') { - // createElement - if (node.argument?.callee?.property?.name === 'createElement' && !state.importedComponent) { - state.importedComponent = true - const reactCreateArguments = node.argument.arguments - reactCreateArguments.push(createElement(componentName)) - } - // JSX - if (node.argument?.type === 'JSXElement' && !state.importedComponent) { - state.importedComponent = true - node.argument.children.push(createJSX(componentName)) - } - } - if (node.type === 'JSXElement' && !state.importedComponent) { - node.children.push(createJSX(componentName)) - } -} - -function defaultJudgePage(filePath: string) { - // 兼容 windows 路径 - const formatFilePath = filePath.replace(/\\/g, '/') - return /(package-.+\/)?pages\/[A-Za-z0-9-]+\/index\.[tj]sx$/.test(formatFilePath) -} diff --git a/loaders/taro-inject-component-loader/tsconfig.json b/loaders/taro-inject-component-loader/tsconfig.json deleted file mode 100644 index 87e73ee..0000000 --- a/loaders/taro-inject-component-loader/tsconfig.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs - "include": ["src", "types"], - "compilerOptions": { - "module": "esnext", - "lib": ["dom", "esnext"], - "importHelpers": true, - // output .d.ts declaration files for consumers - "declaration": true, - // output .js.map sourcemap files for consumers - "sourceMap": true, - // match output dir to input dir. e.g. dist/index instead of dist/src/index - "rootDir": "./src", - // stricter type-checking for stronger correctness. Recommended by TS - "strict": true, - // linter checks for common issues - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative - "noUnusedLocals": true, - "noUnusedParameters": true, - // use Node's module resolution algorithm, instead of the legacy TS one - "moduleResolution": "node", - // transpile JSX to React.createElement - "jsx": "react", - // interop between ESM and CJS modules. Recommended by TS - "esModuleInterop": true, - // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS - "skipLibCheck": true, - // error out if import and file system have a casing mismatch. Recommended by TS - "forceConsistentCasingInFileNames": true, - // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` - "noEmit": true, - } -} diff --git a/package.json b/package.json index fe1effd..9394952 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,7 @@ "dev:qq": "npm run build:qq -- --watch", "dev:jd": "npm run build:jd -- --watch", "dev:quickapp": "npm run build:quickapp -- --watch", - "test": "jest", - "update-iconfont": "npx iconfont-taro" + "test": "jest" }, "browserslist": [ "last 3 versions", @@ -54,16 +53,12 @@ "@tarojs/shared": "3.6.13", "@tarojs/taro": "3.6.13", "babel-plugin-import": "^1.13.8", - "bignumber": "^1.1.0", - "bignumber.js": "^9.1.2", "cross-env": "^7.0.3", "crypto-js": "^3.3.0", - "dayjs": "^1.11.9", "immer": "^10.1.1", "react": "^18.0.0", "react-dom": "^18.0.0", "taro-react-echarts": "^1.2.2", - "weapp-qrcode": "^1.0.0", "zustand": "^4.5.4" }, "devDependencies": { diff --git a/src/app.config.js b/src/app.config.js index 85fa301..541f6e0 100644 --- a/src/app.config.js +++ b/src/app.config.js @@ -1,4 +1,3 @@ -import { useGlobalIconFont } from "./components/iconfont/helper"; export default defineAppConfig({ pages: [ "pages/index/index", @@ -9,5 +8,4 @@ export default defineAppConfig({ navigationBarBackgroundColor: "#fff", navigationBarTextStyle: "black", }, - usingComponents: Object.assign(useGlobalIconFont()), }); diff --git a/src/components/color-diy/index.jsx b/src/components/color-diy/index.jsx index d24c1bb..1c3697a 100644 --- a/src/components/color-diy/index.jsx +++ b/src/components/color-diy/index.jsx @@ -34,127 +34,6 @@ export default function Index() { }, { left: 0 // 透明度 }], - colorList: [{ - r: 255, - g: 0, - b: 0, - a: 1 - }, { - r: 233, - g: 30, - b: 99, - a: 1 - }, { - r: 156, - g: 39, - b: 176, - a: 1 - }, { - r: 103, - g: 58, - b: 183, - a: 1 - }, { - r: 12, - g: 27, - b: 230, - a: 1 - }, { - r: 63, - g: 81, - b: 181, - a: 1 - }, { - r: 33, - g: 150, - b: 243, - a: 1 - }, { - r: 3, - g: 169, - b: 244, - a: 1 - }, { - r: 0, - g: 188, - b: 212, - a: 1 - }, { - r: 0, - g: 150, - b: 136, - a: 1 - }, { - r: 76, - g: 175, - b: 80, - a: 1 - }, { - r: 50, - g: 250, - b: 3, - a: 1 - }, { - r: 139, - g: 195, - b: 74, - a: 1 - }, { - r: 205, - g: 220, - b: 57, - a: 1 - }, { - r: 255, - g: 235, - b: 59, - a: 1 - }, { - r: 255, - g: 193, - b: 7, - a: 1 - }, { - r: 255, - g: 152, - b: 0, - a: 1 - }, { - r: 255, - g: 87, - b: 34, - a: 1 - }, { - r: 121, - g: 85, - b: 72, - a: 1 - }, { - r: 0, - g: 0, - b: 0, - a: 1 - }, { - r: 158, - g: 158, - b: 158, - a: 1 - }, { - r: 255, - g: 255, - b: 255, - a: 1 - }, { - r: 0, - g: 0, - b: 0, - a: 0.5 - }, { - r: 0, - g: 0, - b: 0, - a: 0 - }] }) useEffect(() => { @@ -470,7 +349,7 @@ export default function Index() { b: Math.round(rgb.b) }; } - const { bgcolor, point, rgba, colorList } = data + const { bgcolor, point, rgba } = data return ( @@ -479,12 +358,16 @@ export default function Index() { 取消 确认 + + + + @@ -503,18 +386,6 @@ export default function Index() { - - { - colorList.map((item, index) => { - return - - - - - }) - } - - ) diff --git a/src/components/color-diy/index.less b/src/components/color-diy/index.less index 6fd99bf..126f9c6 100644 --- a/src/components/color-diy/index.less +++ b/src/components/color-diy/index.less @@ -303,37 +303,3 @@ writing-mode: vertical-lr; font-weight: bold; } - -.cp-option { - margin: 60px 20px 40px; - display: grid; - grid-template-columns: repeat(8, 1fr); - gap: 20px; - box-sizing: border-box; -} - -.cp-option-item { - width: 50rpx; - height: 50rpx; - margin: 0 auto; - border-radius: 10rpx; - background-color: #fff; - background-image: linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%, #eee), - linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%, #eee); - background-size: 36rpx 36rpx; - background-position: 0 0, 18rpx 18rpx; - border: 1px #eee solid; - overflow: hidden; -} - -.cp-option-item-content { - width: 50rpx; - height: 50rpx; - background: rgba(255, 0, 0, 0.5); -} - -.cp-option-item:active { - transition: all 0.3s; - -webkit-transform: scale(1.1); - transform: scale(1.1); -} diff --git a/src/components/icon/index.jsx b/src/components/icon/index.jsx deleted file mode 100644 index 9ec3846..0000000 --- a/src/components/icon/index.jsx +++ /dev/null @@ -1,17 +0,0 @@ -import { View } from '@tarojs/components' -import IconFont from '@/components/iconfont' -import './index.less' - -export default function Index({ name, size = 25, style, color, onClick, className }) { - return ( - onClick && onClick()} - > - - - ) -} diff --git a/src/components/icon/index.less b/src/components/icon/index.less deleted file mode 100644 index ee16ec3..0000000 --- a/src/components/icon/index.less +++ /dev/null @@ -1,7 +0,0 @@ -.iconfont { - display: flex; - align-items: center; - justify-content: center; - padding: 0 4rpx; - display: inline-block; -} \ No newline at end of file diff --git a/src/components/iconfont/helper.d.ts b/src/components/iconfont/helper.d.ts deleted file mode 100644 index 24a9a53..0000000 --- a/src/components/iconfont/helper.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -/* eslint-disable */ -export declare var useGlobalIconFont: () => { iconfont: string }; diff --git a/src/components/iconfont/helper.js b/src/components/iconfont/helper.js deleted file mode 100644 index 2caa692..0000000 --- a/src/components/iconfont/helper.js +++ /dev/null @@ -1,9 +0,0 @@ -/* eslint-disable */ -const useGlobalIconFont = () => { - return { - iconfont: `components/iconfont/${process.env.TARO_ENV}/${process.env.TARO_ENV}`, - }; -}; - -// es modules is unavaiable. -module.exports.useGlobalIconFont = useGlobalIconFont; diff --git a/src/components/iconfont/index.d.ts b/src/components/iconfont/index.d.ts deleted file mode 100644 index 7a228df..0000000 --- a/src/components/iconfont/index.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* eslint-disable */ -import React, { FunctionComponent } from 'react'; - -interface Props { - name: 'icon-xiaoshui3' | 'icon-xiaoshui2' | 'icon-xiaoshui1' | 'icon-piandi' | 'icon-piangao' | 'icon-qianshui2' | 'icon-qianshui1' | 'icon-qingxing2' | 'icon-shimian1' | 'icon-qingxing1' | 'icon-shenshui2' | 'icon-shimian2' | 'icon-rushuixiaoshuai' | 'icon-yandong2' | 'icon-yandong1' | 'icon-shenshui1' | 'icon-zongshuimian' | 'icon-shuimianxiaoshuai' | 'icon-qingxingcishu' | 'icon-xitongshezhi1' | 'icon-nvxingzhushou' | 'icon-shiwen' | 'icon-xieyang' | 'icon-tiwen' | 'icon-xieya' | 'icon-xinshuai' | 'icon-shuimian' | 'icon-huodongjilu' | 'icon-ECG' | 'icon-HRV' | 'icon-jibu' | 'icon-beijianhuren' | 'icon-xitongshezhi' | 'icon-yuyanqiehuan' | 'icon-shebeidingwei' | 'icon-wodequanyi' | 'icon-jinjilianxiren' | 'icon-jianhuren' | 'icon-a-huaban24' | 'icon-a-huaban14' | 'icon-a-huaban11' | 'icon-a-huaban25' | 'icon-a-huaban7' | 'icon-a-huaban23' | 'icon-a-huaban15' | 'icon-a-huaban141' | 'icon-a-huaban2' | 'icon-a-huaban12' | 'icon-a-huaban22' | 'icon-a-huaban21' | 'icon-a-huaban26' | 'icon-a-huaban1' | 'icon-a-huaban13' | 'icon-shen' | 'icon-gan' | 'icon-pi' | 'icon-xinzang' | 'icon-duigou' | 'icon-a-ziyuan77' | 'icon-xiangxia' | 'icon-xiangxia1' | 'icon-shangyiye' | 'icon-xiayiye' | 'icon-a-ziyuan15' | 'icon-a-ziyuan21' | 'icon-a-ziyuan42' | 'icon-a-ziyuan29' | 'icon-a-ziyuan31'; - size?: number; - color?: string | string[]; - style?: React.CSSProperties; -} - -declare const IconFont: FunctionComponent; - -export default IconFont; diff --git a/src/components/iconfont/index.js b/src/components/iconfont/index.js deleted file mode 100644 index 9236f4b..0000000 --- a/src/components/iconfont/index.js +++ /dev/null @@ -1,7 +0,0 @@ -/* eslint-disable */ - -const IconFont = () => { - return null; -}; - -export default IconFont; diff --git a/src/components/iconfont/index.weapp.js b/src/components/iconfont/index.weapp.js deleted file mode 100644 index 731305b..0000000 --- a/src/components/iconfont/index.weapp.js +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-disable */ - -import React from 'react'; -import Taro from '@tarojs/taro'; - -const IconFont = (props) => { - const { name, size, color, style } = props; - - return ; -}; - -IconFont.defaultProps = { - size: 18, -}; - -export default IconFont; diff --git a/src/components/iconfont/weapp/weapp.js b/src/components/iconfont/weapp/weapp.js deleted file mode 100644 index f090ef4..0000000 --- a/src/components/iconfont/weapp/weapp.js +++ /dev/null @@ -1,63 +0,0 @@ -Component({ - properties: { - // icon-xiaoshui3 | icon-xiaoshui2 | icon-xiaoshui1 | icon-piandi | icon-piangao | icon-qianshui2 | icon-qianshui1 | icon-qingxing2 | icon-shimian1 | icon-qingxing1 | icon-shenshui2 | icon-shimian2 | icon-rushuixiaoshuai | icon-yandong2 | icon-yandong1 | icon-shenshui1 | icon-zongshuimian | icon-shuimianxiaoshuai | icon-qingxingcishu | icon-xitongshezhi1 | icon-nvxingzhushou | icon-shiwen | icon-xieyang | icon-tiwen | icon-xieya | icon-xinshuai | icon-shuimian | icon-huodongjilu | icon-ECG | icon-HRV | icon-jibu | icon-beijianhuren | icon-xitongshezhi | icon-yuyanqiehuan | icon-shebeidingwei | icon-wodequanyi | icon-jinjilianxiren | icon-jianhuren | icon-a-huaban24 | icon-a-huaban14 | icon-a-huaban11 | icon-a-huaban25 | icon-a-huaban7 | icon-a-huaban23 | icon-a-huaban15 | icon-a-huaban141 | icon-a-huaban2 | icon-a-huaban12 | icon-a-huaban22 | icon-a-huaban21 | icon-a-huaban26 | icon-a-huaban1 | icon-a-huaban13 | icon-shen | icon-gan | icon-pi | icon-xinzang | icon-duigou | icon-a-ziyuan77 | icon-xiangxia | icon-xiangxia1 | icon-shangyiye | icon-xiayiye | icon-a-ziyuan15 | icon-a-ziyuan21 | icon-a-ziyuan42 | icon-a-ziyuan29 | icon-a-ziyuan31 - name: { - type: String, - }, - // string | string[] - color: { - type: null, - observer: function(color) { - this.setData({ - colors: this.fixColor(), - isStr: typeof color === 'string', - }); - } - }, - size: { - type: Number, - value: 18, - observer: function(size) { - this.setData({ - svgSize: size / 750 * wx.getSystemInfoSync().windowWidth, - }); - }, - }, - }, - data: { - colors: '', - svgSize: 18 / 750 * wx.getSystemInfoSync().windowWidth, - quot: '"', - isStr: true, - }, - methods: { - fixColor: function() { - var color = this.data.color; - var hex2rgb = this.hex2rgb; - - if (typeof color === 'string') { - return color.indexOf('#') === 0 ? hex2rgb(color) : color; - } - - return color.map(function (item) { - return item.indexOf('#') === 0 ? hex2rgb(item) : item; - }); - }, - hex2rgb: function(hex) { - var rgb = []; - - hex = hex.substr(1); - - if (hex.length === 3) { - hex = hex.replace(/(.)/g, '$1$1'); - } - - hex.replace(/../g, function(color) { - rgb.push(parseInt(color, 0x10)); - return color; - }); - - return 'rgb(' + rgb.join(',') + ')'; - } - } -}); diff --git a/src/components/iconfont/weapp/weapp.json b/src/components/iconfont/weapp/weapp.json deleted file mode 100644 index a89ef4d..0000000 --- a/src/components/iconfont/weapp/weapp.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "component": true, - "usingComponents": {} -} diff --git a/src/components/iconfont/weapp/weapp.wxml b/src/components/iconfont/weapp/weapp.wxml deleted file mode 100644 index ece0765..0000000 --- a/src/components/iconfont/weapp/weapp.wxml +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/components/iconfont/weapp/weapp.wxss b/src/components/iconfont/weapp/weapp.wxss deleted file mode 100644 index 9f68d1a..0000000 --- a/src/components/iconfont/weapp/weapp.wxss +++ /dev/null @@ -1,3 +0,0 @@ -.icon { - background-repeat: no-repeat; -} diff --git a/src/pages/funList/index.jsx b/src/pages/funList/index.jsx index 6091fae..42a417e 100644 --- a/src/pages/funList/index.jsx +++ b/src/pages/funList/index.jsx @@ -1,6 +1,6 @@ import { View } from '@tarojs/components' import './index.less' -import { Form, Toast, Cell, Slider, Radio, Switch, Stepper } from "@taroify/core" +import { Form, Toast, Cell, Slider, Radio, Switch, Stepper, Button } from "@taroify/core" import { useCallback, useState } from 'react' import { hex, strInsert } from '@/utils/sendOrder' import { debounce } from '@/utils/index' @@ -66,8 +66,8 @@ export default function Index() { break; } sendCode(str) - } + return (
@@ -154,7 +154,6 @@ export default function Index() { handleChange(e, 'AI')} checked={ruleForm.AI} /> -
diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx index 4d7cf24..138e1fd 100644 --- a/src/pages/index/index.jsx +++ b/src/pages/index/index.jsx @@ -1,16 +1,19 @@ import { View } from '@tarojs/components' import './index.less' import { Button } from "@taroify/core" -import { Scan } from "@taroify/icons" import BLESDK from '../../utils/ble' import Taro, { useDidShow } from '@tarojs/taro' import { useState } from 'react' +import { getInitData } from '@/utils/sendOrder' export default function Index() { const [deviceInfo, setDeviceInfo] = useState(BLESDK.deviceInfo) + const [disabled, setDisabled] = useState(!!BLESDK.deviceInfo.state) + const [loading, setLoading] = useState(false) const deviceCallBack = () => { setDeviceInfo({ ...BLESDK.deviceInfo }) if (BLESDK.deviceInfo.state) { + setDisabled(true) } } const lookSleep = () => { @@ -21,7 +24,20 @@ export default function Index() { useDidShow(() => { BLESDK.deviceCallBack(deviceCallBack) setDeviceInfo({ ...BLESDK.deviceInfo }) + setDisabled(!!BLESDK.deviceInfo.state) }) + + const searchBluetooth = () => { + BLESDK.startBluetoothDevicesDiscovery() + setLoading(true) + setDisabled(true) + setTimeout(() => { + BLESDK.stopBluetoothDevicesDiscovery(); + setLoading(false) + setDisabled(!!BLESDK.deviceInfo.state) + }, 6000) + } + return ( @@ -38,7 +54,9 @@ export default function Index() { {deviceInfo.name ? deviceInfo.state ? '已连接' : '未连接' : '--'} - + + +
) } diff --git a/src/pages/index/index.less b/src/pages/index/index.less index 33145aa..4ff1320 100644 --- a/src/pages/index/index.less +++ b/src/pages/index/index.less @@ -17,3 +17,8 @@ } } } + +.connect { + position: fixed; + bottom: 60px; +} diff --git a/src/utils/ble.js b/src/utils/ble.js index f0a17a5..018a6b9 100644 --- a/src/utils/ble.js +++ b/src/utils/ble.js @@ -1,5 +1,5 @@ import Taro from "@tarojs/taro"; -import { handshake, asyncDate } from "./sendOrder"; +import { handshake1, handshake2 } from "./sendOrder"; import useStore from "@/store/index"; import { aes128Decrypt } from "@/utils/index"; import TASK from "./taskQueue"; @@ -94,7 +94,6 @@ class Bluetooth { return Taro.openBluetoothAdapter({ success: () => { console.log("初始化蓝牙模块"); - this.startBluetoothDevicesDiscovery() this.isInit = true; }, fail: (err) => { @@ -128,6 +127,7 @@ class Bluetooth { }, }); } + console.log("未搜索到设备"); this.isFindBt && this.clearTimeoutFn("isFindBt"); }, 6000); }, @@ -228,7 +228,7 @@ class Bluetooth { state: true, success: (res) => { console.log("连接成功"); - + handshake1() this.callBack(this.deviceInfo); }, fail: (err) => this.fail(err), @@ -238,31 +238,23 @@ class Bluetooth { onBLECharacteristicValueChange(fn) { Taro.onBLECharacteristicValueChange((data) => { let bytes = new Uint8Array(data.value); - let aesBytes = null; let value = String(this.ab2hex(bytes)); - // 长度在16内的需要解密 - if (bytes.byteLength == 17 && bytes[0] == 0xfc) { - let aesText = this.strInsert(aes128Decrypt(value.substring(2))).split(":"); - let bf = new ArrayBuffer(aesText.length); - let dv = new DataView(bf); - aesText.forEach((item, index) => { - dv.setUint8(index, `0x${item}`); - }); - aesBytes = new Uint8Array(bf); + + // 第二次握手 + if (bytes[2] == 0xea && bytes[3] == 0x01) { + handshake2() } - // 获取电量 - if (aesBytes && aesBytes[1] == 0xa1 && aesBytes[2] == 0x07 && aesBytes[3] == 0xb3) { - useStore.setState((state) => { - state.battery = aesBytes[4]; - }); - } - console.log(`设备回复====>${bytes.byteLength == 17 ? String(this.ab2hex(aesBytes)) : value}`); + console.log(`设备回复====>${value}`); TASK.executeTask(); - fn && fn(bytes, aesBytes, value); + fn && fn(bytes, value); }); } // 向蓝牙写入数据 writeBleValue(value) { + if (!this.deviceInfo.state) { + console.log("蓝牙未连接") + return + } console.log("发送指令====>" + String(this.ab2hex(value)).toLocaleUpperCase()); return Taro.writeBLECharacteristicValue({ deviceId: this.deviceInfo.deviceId, @@ -294,8 +286,8 @@ class Bluetooth { } //停止搜寻附近的蓝牙外围设备 stopBluetoothDevicesDiscovery() { - this.isFindBt && this.clearTimeoutFn("isFindBt"); Taro.stopBluetoothDevicesDiscovery(); + this.isFindBt && this.clearTimeoutFn("isFindBt"); console.log("停止搜寻"); } // 断开与蓝牙低功耗设备的连接 @@ -311,7 +303,6 @@ class Bluetooth { }, }); }) - } // 设备响应回调 deviceCallBack(fn) { diff --git a/src/utils/index.js b/src/utils/index.js index ba28aa2..1038861 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,4 +1,3 @@ -import dayjs from "dayjs"; import Taro from "@tarojs/taro"; import { useEffect, useRef, useState, useCallback } from "react"; import CryptoJS from "crypto-js"; diff --git a/src/utils/sendOrder.js b/src/utils/sendOrder.js index 13bb01d..a404115 100644 --- a/src/utils/sendOrder.js +++ b/src/utils/sendOrder.js @@ -14,9 +14,15 @@ export const hex = (hex) => { return hex < 16 ? '0' + hex.toString(16) : String(hex.toString(16)) } -// 握手 -export function handshake() { - let list = strInsert(aes128Encrypt(`10a1010259414B2D56302E302E310000`)) +// 第一次握手 +export function handshake1() { + let list = strInsert(`7B12EA01014775696565652d56312e302e30`) + TASK.addTask(list) +} + +// 第二次握手 +export function handshake2() { + let list = strInsert(`7B0EEA0101436172652079616b6b`) TASK.addTask(list) } @@ -53,19 +59,39 @@ export function asyncDate() { TASK.addTask(strInsert(aes128Encrypt(str))); } -// 获取版本号 -export function getVersions() { - TASK.addTask(strInsert(aes128Encrypt(`10a102b1000000000000000000000000`))); -} -// 重启 -export function restart() { - TASK.addTask(strInsert(aes128Encrypt(`0906800000`))); -} -// 获取新版睡眠 -export function getNewSleep() { - TASK.addTask(strInsert(aes128Encrypt(`10A31a00ff00000000000000000000`))); -} -// 新版睡眠-接收回复 -export function sleepResReply(type, date, num) { - TASK.addTask(strInsert(aes128Encrypt(`10A3${hex(type)}${hex(date)}${hex(num)}0000000000000000000000`))); +// -----------------获取--------------------- +export function getInitData() { + // 话筒音量 + TASK.addTask(strInsert(`7B05EA05B100`)); + + // 音乐音量 + TASK.addTask(strInsert(`7B05EA06B100`)); + + // 音源设置 + TASK.addTask(strInsert(`7B05EA07B100`)); + + // 蓝牙开关 + TASK.addTask(strInsert(`7B05EA08B100`)); + + // 声卡开关 + TASK.addTask(strInsert(`7B05EA09B100`)); + + // 播放模式 + TASK.addTask(strInsert(`7B05EA0AB100`)); + + // 音乐控制 + TASK.addTask(strInsert(`7B05EA0BB100`)); + + // 超低音强度 + TASK.addTask(strInsert(`7B05EA0CB100`)); + + // 混响模式 + TASK.addTask(strInsert(`7B05EA0DB100`)); + + // 话筒混响 + TASK.addTask(strInsert(`7B05EA0EB100`)); + + // AI + TASK.addTask(strInsert(`7B05EA11B100`)); } + diff --git a/src/utils/taskQueue.js b/src/utils/taskQueue.js index d6b51cb..25bbd79 100644 --- a/src/utils/taskQueue.js +++ b/src/utils/taskQueue.js @@ -6,22 +6,28 @@ class taskQueue { overtime = null addTask(buffer) { + if (!BLESDK.deviceInfo.state) return this.list.push(buffer) - if (!this.isExecute) { - this.isExecute = true - this.executeTask() - } + + if (this.isExecute) return + this.executeTask() } executeTask() { this.isExecute = !!this.list.length if (!this.list.length) return - BLESDK.writeBleValue(new Uint8Array(['0x7b', ...this.list[0]]).buffer) + if (!BLESDK.deviceInfo.state) { + this.list = [] + this.isExecute = !!this.list.length + return + } + BLESDK.writeBleValue(new Uint8Array([...this.list[0]]).buffer) this.list.shift() this.overtime = setTimeout(() => { + this.stopOverTime() this.executeTask() - }, 1000) + }, 800) } stopOverTime() { clearTimeout(this.overtime) diff --git a/yarn.lock b/yarn.lock index e939cb2..ddb884e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3798,16 +3798,6 @@ big.js@^5.2.2: resolved "https://registry.npmmirror.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328" integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ== -bignumber.js@^9.1.2: - version "9.1.2" - resolved "https://registry.npmmirror.com/bignumber.js/-/bignumber.js-9.1.2.tgz#b7c4242259c008903b13707983b5f4bbd31eda0c" - integrity sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug== - -bignumber@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/bignumber/-/bignumber-1.1.0.tgz#e6ab0a743da5f3ea018e5c17597d121f7868c159" - integrity sha512-EGqHCKkEAwVwufcEOCYhZQqdVH+7cNCyPZ9yxisYvSjHFB+d9YcGMvorsFpeN5IJpC+lC6K+FHhu8+S4MgJazw== - binary-extensions@^2.0.0: version "2.2.0" resolved "https://registry.npmmirror.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" @@ -4808,11 +4798,6 @@ data-urls@^4.0.0: whatwg-mimetype "^3.0.0" whatwg-url "^12.0.0" -dayjs@^1.11.9: - version "1.11.9" - resolved "https://registry.npmmirror.com/dayjs/-/dayjs-1.11.9.tgz#9ca491933fadd0a60a2c19f6c237c03517d71d1a" - integrity sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA== - debug@2.6.9: version "2.6.9" resolved "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -5973,7 +5958,7 @@ ext-name@^5.0.0: ext-list "^2.0.0" sort-keys-length "^1.0.0" -extend@^3.0.2, extend@~3.0.2: +extend@~3.0.2: version "3.0.2" resolved "https://registry.npmmirror.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== @@ -12004,13 +11989,6 @@ wcwidth@^1.0.1: dependencies: defaults "^1.0.3" -weapp-qrcode@^1.0.0: - version "1.0.0" - resolved "https://registry.npmmirror.com/weapp-qrcode/-/weapp-qrcode-1.0.0.tgz#4f3b4b4e7d37710c513439166734587859aebbfc" - integrity sha512-4sa3W0rGDVJ9QaeZpAKlAuUxVyjhDwiUqHyGK/jJMsRMXnhb4yO8qWU/pZruMo+iT5J6CraS67lDMFb1VY+RaA== - dependencies: - extend "^3.0.2" - webidl-conversions@^7.0.0: version "7.0.0" resolved "https://registry.npmmirror.com/webidl-conversions/-/webidl-conversions-7.0.0.tgz#256b4e1882be7debbf01d05f0aa2039778ea080a"