diff --git a/tixwork-taro/.env.dev b/tixwork-taro/.env.dev new file mode 100644 index 00000000..a3f1b48d --- /dev/null +++ b/tixwork-taro/.env.dev @@ -0,0 +1,2 @@ +# 配置文档参考 https://taro-docs.jd.com/docs/next/env-mode-config +# TARO_APP_ID="开发环境下的小程序appid" \ No newline at end of file diff --git a/tixwork-taro/.env.prod b/tixwork-taro/.env.prod new file mode 100644 index 00000000..be6f45ea --- /dev/null +++ b/tixwork-taro/.env.prod @@ -0,0 +1 @@ +# TARO_APP_ID="生产环境下的小程序appid" \ No newline at end of file diff --git a/tixwork-taro/.env.test b/tixwork-taro/.env.test new file mode 100644 index 00000000..0215b61e --- /dev/null +++ b/tixwork-taro/.env.test @@ -0,0 +1 @@ +# TARO_APP_ID="测试环境下的小程序appid" \ No newline at end of file diff --git a/tixwork-taro/.eslintrc.js b/tixwork-taro/.eslintrc.js index cfe2efaf..d7e385b5 100644 --- a/tixwork-taro/.eslintrc.js +++ b/tixwork-taro/.eslintrc.js @@ -6,8 +6,6 @@ module.exports ={ "import/first": "off", "jsx-quotes": "off", "react/sort-comp": [0], - "react/jsx-uses-react": "off", - "react/react-in-jsx-scope": "off", "no-shadow": "off", "react/jsx-curly-brace-presence": "off" } diff --git a/tixwork-taro/.gitignore b/tixwork-taro/.gitignore index 1afc6569..04e76859 100644 --- a/tixwork-taro/.gitignore +++ b/tixwork-taro/.gitignore @@ -7,5 +7,6 @@ node_modules/ .DS_Store .idea deploy_versions/ +.swc diff --git a/tixwork-taro/LICENSE b/tixwork-taro/LICENSE deleted file mode 100644 index dbede0ad..00000000 --- a/tixwork-taro/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 kala - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/tixwork-taro/config/dev.js b/tixwork-taro/config/dev.js deleted file mode 100644 index c4350d5e..00000000 --- a/tixwork-taro/config/dev.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - env: { - NODE_ENV: '"development"' - }, - plugins: [ - // '@tarojs/plugin-react-devtools' - ], - defineConstants: { - }, - mini: {}, - h5: {} -} diff --git a/tixwork-taro/config/dev.ts b/tixwork-taro/config/dev.ts new file mode 100644 index 00000000..2ee1345d --- /dev/null +++ b/tixwork-taro/config/dev.ts @@ -0,0 +1,9 @@ +import type { UserConfigExport } from "@tarojs/cli"; +export default { + logger: { + quiet: false, + stats: true + }, + mini: {}, + h5: {} +} satisfies UserConfigExport diff --git a/tixwork-taro/config/index.js b/tixwork-taro/config/index.js deleted file mode 100644 index ba033a64..00000000 --- a/tixwork-taro/config/index.js +++ /dev/null @@ -1,159 +0,0 @@ -// eslint-disable-next-line import/no-commonjs -const path = require('path'); // 加在最上面 - -const config = { - projectName: 'tixwork-taro', - date: '2022-5-25', - designWidth: 750, - deviceRatio: { - '640': 2.34 / 2, - '750': 1, - '828': 1.81 / 2, - }, - sourceRoot: 'src', - outputRoot: 'dist', - plugins: [], - defineConstants: {}, - copy: { - patterns: [], - options: {}, - }, - framework: 'react', - compiler: { - type: 'webpack5', - prebundle: { //bug 等待处理https://github.com/NervJS/taro/issues/12281 - enable: false, - }, - }, - cache: { - enable: false, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache - }, - alias: { - '@/http': path.resolve(__dirname, '..', 'src/http'), - '@/model': path.resolve(__dirname, '..', 'src/model'), - '@/components': path.resolve(__dirname, '..', 'src/components'), - '@/utils': path.resolve(__dirname, '..', 'src/utils'), - '@/service': path.resolve(__dirname, '..', 'src/service'), - '@/nice-router': path.resolve(__dirname, '..', 'src/nice-router'), - '@/genericpage': path.resolve(__dirname, '..', 'src/genericpage'), - '@/genericform': path.resolve(__dirname, '..', 'src/genericform'), - '@/server-image': path.resolve(__dirname, '..', 'src/server-image'), - '@/listof': path.resolve(__dirname, '..', 'src/listof'), - - }, - mini: { - enableExtract: true, - miniCssExtractPluginOption: { - ignoreOrder: true, - }, - postcss: { - pxtransform: { - enable: true, - config: {}, - }, - url: { - enable: true, - config: { - limit: 40240, // 设定转换尺寸上限 - }, - }, - cssModules: { - enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true - config: { - namingPattern: 'module', // 转换模式,取值为 global/module - generateScopedName: '[name]__[local]___[hash:base64:5]', - }, - }, - }, - webpackChain(chain) { - // chain.plugin('analyzer') - // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, []) - - //lodash 瘦身配置 - // 奇怪行为,需要设置这个https://www.npmjs.com/package/lodash-webpack-plugin - // 也可以移除一些,用来瘦身,目前发现shorthands,coercions,paths是必须的,否则会很诡异 - chain.plugin('lodash-webpack-plugin') - .use(require('lodash-webpack-plugin'), [ - { - shorthands: true, - cloning: true, - caching: true, - collections: true, - exotics: true, - guards: true, - memoizing: true, - coercions: true, - flattening: true, - paths: true, - }]); - - // 将 lodash 单独拆分出来 (防止vendors.js过大) - chain.merge({ - optimization: { - splitChunks: { - cacheGroups: { - lodash: { - name: 'lodash', - priority: 1000, - test(module) { - return /node_modules[\\/]lodash/.test(module.context); - }, - }, - }, - }, - }, - }); - }, - commonChunks(commonChunks) { // 添加 lodash 公共文件 - commonChunks.push('lodash'); - return commonChunks; - }, - }, - h5: { - publicPath: '/', - staticDirectory: 'static', - router: { - mode: 'browser', // 或者是 'hash' - }, - output: { - filename: 'js/[name].[hash].js', - chunkFilename: 'js/[name].[chunkhash].js', - }, - imageUrlLoaderOption: { - limit: 5000, - name: 'static/images/[name].[hash].[ext]', - }, - miniCssExtractPluginOption: { - filename: 'css/[name].[hash].css', - chunkFilename: 'css/[name].[chunkhash].css', - }, - postcss: { - autoprefixer: { - enable: true, - config: {}, - }, - cssModules: { - enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true - config: { - namingPattern: 'module', // 转换模式,取值为 global/module - generateScopedName: '[name]__[local]___[hash:base64:5]', - }, - }, - }, - }, - rn: { - appName: 'NiceRouterDemo', - postcss: { - cssModules: { - enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true - }, - }, - }, -}; - -module.exports = function(merge) { - if (process.env.NODE_ENV === 'development') { - return merge({}, config, require('./dev')); - } - return merge({}, config, require('./prod')); -}; diff --git a/tixwork-taro/config/index.ts b/tixwork-taro/config/index.ts new file mode 100644 index 00000000..4ed6f903 --- /dev/null +++ b/tixwork-taro/config/index.ts @@ -0,0 +1,166 @@ +// eslint-disable-next-line import/no-commonjs +import { defineConfig, type UserConfigExport } from '@tarojs/cli'; +import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'; +import devConfig from './dev'; +import prodConfig from './prod'; +import path from 'path'; + +// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数 +// @ts-ignore +export default defineConfig(async (merge, { command, mode }) => { + const baseConfig: UserConfigExport = { + projectName: 'tixwork-taro', + date: '2022-5-25', + designWidth: 750, + deviceRatio: { + 640: 2.34 / 2, + 750: 1, + 375: 2, + 828: 1.81 / 2, + }, + sourceRoot: 'src', + outputRoot: 'dist', + plugins: [], + defineConstants: {}, + copy: { + patterns: [], + options: {}, + }, + framework: 'react', + compiler: 'webpack5', + cache: { + enable: false, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache + }, + alias: { + '@/http': path.resolve(__dirname, '..', 'src/http'), + '@/model': path.resolve(__dirname, '..', 'src/model'), + '@/components': path.resolve(__dirname, '..', 'src/components'), + '@/utils': path.resolve(__dirname, '..', 'src/utils'), + '@/service': path.resolve(__dirname, '..', 'src/service'), + '@/nice-router': path.resolve(__dirname, '..', 'src/nice-router'), + '@/genericpage': path.resolve(__dirname, '..', 'src/genericpage'), + '@/genericform': path.resolve(__dirname, '..', 'src/genericform'), + '@/server-image': path.resolve(__dirname, '..', 'src/server-image'), + '@/listof': path.resolve(__dirname, '..', 'src/listof'), + + }, + mini: { + miniCssExtractPluginOption: { + ignoreOrder: true, + }, + postcss: { + pxtransform: { + enable: true, + config: {}, + }, + url: { + enable: true, + config: { + limit: 40240, // 设定转换尺寸上限 + }, + }, + cssModules: { + enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true + config: { + namingPattern: 'module', // 转换模式,取值为 global/module + generateScopedName: '[name]__[local]___[hash:base64:5]', + }, + }, + }, + webpackChain(chain) { + chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin); + // chain.plugin('analyzer') + // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, []) + + //lodash 瘦身配置 + // 奇怪行为,需要设置这个https://www.npmjs.com/package/lodash-webpack-plugin + // 也可以移除一些,用来瘦身,目前发现shorthands,coercions,paths是必须的,否则会很诡异 + chain.plugin('lodash-webpack-plugin') + .use(require('lodash-webpack-plugin'), [ + { + shorthands: true, + cloning: true, + caching: true, + collections: true, + exotics: true, + guards: true, + memoizing: true, + coercions: true, + flattening: true, + paths: true, + }]); + + // 将 lodash 单独拆分出来 (防止vendors.js过大) + chain.merge({ + optimization: { + splitChunks: { + cacheGroups: { + lodash: { + name: 'lodash', + priority: 1000, + test(module) { + return /node_modules[\\/]lodash/.test(module.context); + }, + }, + }, + }, + }, + }); + }, + commonChunks(commonChunks) { // 添加 lodash 公共文件 + commonChunks.push('lodash'); + return commonChunks; + }, + }, + h5: { + publicPath: '/', + staticDirectory: 'static', + router: { + mode: 'browser', // 或者是 'hash' + }, + output: { + filename: 'js/[name].[hash:8].js', + chunkFilename: 'js/[name].[chunkhash:8].js', + }, + imageUrlLoaderOption: { + limit: 5000, + name: 'static/images/[name].[hash].[ext]', + }, + miniCssExtractPluginOption: { + ignoreOrder: true, + filename: 'css/[name].[hash].css', + chunkFilename: 'css/[name].[chunkhash].css', + }, + postcss: { + autoprefixer: { + enable: true, + config: {}, + }, + cssModules: { + enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true + config: { + namingPattern: 'module', // 转换模式,取值为 global/module + generateScopedName: '[name]__[local]___[hash:base64:5]', + }, + }, + }, + webpackChain(chain) { + chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin); + }, + }, + rn: { + appName: 'TixworkRN', + postcss: { + cssModules: { + enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true + }, + }, + }, + }; + if (process.env.NODE_ENV === 'development') { + // 本地开发构建配置(不混淆压缩) + return merge({}, baseConfig, devConfig); + } + // 生产构建配置(默认开启压缩混淆等) + return merge({}, baseConfig, prodConfig); +}); diff --git a/tixwork-taro/config/prod.js b/tixwork-taro/config/prod.ts similarity index 72% rename from tixwork-taro/config/prod.js rename to tixwork-taro/config/prod.ts index 890680f8..d8acd74b 100644 --- a/tixwork-taro/config/prod.js +++ b/tixwork-taro/config/prod.ts @@ -1,23 +1,23 @@ +import type { UserConfigExport } from "@tarojs/cli"; // 作为h5嵌入到其他webview中时,如果需要调试,打开注释 // const vConsolePlugin = require('vconsole-webpack-plugin'); -module.exports = { - env: { - NODE_ENV: '"production"' - }, - defineConstants: { - }, + +export default { mini: {}, h5: { /** - * 如果h5端编译后体积过大,可以使用webpack-bundle-analyzer插件对打包体积进行分析。 - * 参考代码如下: - * webpackChain (chain) { - * chain.plugin('analyzer') - * .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, []) - * } + * WebpackChain 插件配置 + * @docs https://github.com/neutrinojs/webpack-chain */ + // webpackChain (chain) { + // /** + // * 如果 h5 端编译后体积过大,可以使用 webpack-bundle-analyzer 插件对打包体积进行分析。 + // * @docs https://github.com/webpack-contrib/webpack-bundle-analyzer + // */ + // chain.plugin('analyzer') + // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, []) // webpackChain (chain) { // chain.plugin('vconsole-webpack-plugin').use(vConsolePlugin, [{enable: true}]); @@ -35,6 +35,7 @@ module.exports = { // chain.plugin('analyzer') // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, []) + // /** // * 如果 h5 端首屏加载时间过长,可以使用 prerender-spa-plugin 插件预加载首页。 // * @docs https://github.com/chrisvfritz/prerender-spa-plugin @@ -51,4 +52,4 @@ module.exports = { // })) // } } -} +} satisfies UserConfigExport diff --git a/tixwork-taro/package.json b/tixwork-taro/package.json index 8a0f2907..67c02583 100644 --- a/tixwork-taro/package.json +++ b/tixwork-taro/package.json @@ -1,117 +1,127 @@ { - "name": "tixwork-taro", - "version": "2.0.0", - "private": true, - "description": "rebuild from nice-router-taro", - "templateInfo": { - "name": "default", - "typescript": true, - "css": "less" - }, - "scripts": { - "build:weapp": "taro build --type weapp", - "build:swan": "taro build --type swan", - "build:alipay": "taro build --type alipay", - "build:tt": "taro build --type tt", - "build:h5": "taro build --type h5", - "build:rn": "taro build --type rn", - "build:qq": "taro build --type qq", - "build:jd": "taro build --type jd", - "build:quickapp": "taro build --type quickapp", - "dev:weapp": "npm run build:weapp -- --watch", - "dev:swan": "npm run build:swan -- --watch", - "dev:alipay": "npm run build:alipay -- --watch", - "dev:tt": "npm run build:tt -- --watch", - "dev:h5": "npm run build:h5 -- --watch", - "dev:rn": "npm run build:rn -- --watch", - "dev:qq": "npm run build:qq -- --watch", - "dev:jd": "npm run build:jd -- --watch", - "dev:quickapp": "npm run build:quickapp -- --watch", - "format": "yarn prettier && yarn lint --fix", - "prettier": "prettier --write \"./src/**/*\" ", - "lint:fix": "eslint --fix --ext .js,.jsx,.ts,.tsx src", - "lint": "eslint --ext .js,.jsx,.ts,.tsx src", - "precommit": "lint-staged" - }, - "browserslist": [ - "last 3 versions", - "Android >= 4.1", - "ios >= 8" - ], - "author": "Kala ", - "license": "MIT", - "dependencies": { - "@babel/runtime": "^7.14.6", - "@tarojs/components": "3.5.3", - "@tarojs/helper": "3.5.3", - "@tarojs/plugin-framework-react": "3.5.3", - "@tarojs/plugin-platform-alipay": "3.5.3", - "@tarojs/plugin-platform-jd": "3.5.3", - "@tarojs/plugin-platform-qq": "3.5.3", - "@tarojs/plugin-platform-swan": "3.5.3", - "@tarojs/plugin-platform-tt": "3.5.3", - "@tarojs/plugin-platform-weapp": "3.5.3", - "@tarojs/react": "3.5.3", - "@tarojs/router": "3.5.3", - "@tarojs/runtime": "3.5.3", - "@tarojs/shared": "3.5.3", - "@tarojs/taro": "3.5.3", - "@tarojs/taro-h5": "3.5.3", - "async-validator": "^3.5.2", - "classnames": "^2.3.1", - "crypto-es": "^1.2.7", - "global": "^4.4.0", - "jwt-decode": "^3.1.2", - "lodash": "^4.17.11", - "mime": "^2.5.2", - "nervjs": "^1.5.7", - "path-to-regexp": "^3.0.0", - "qr.js": "^0.0.0", - "react": "^18.0.0", - "react-dom": "^18.0.0", - "vconsole": "^3.7.0" - }, - "devDependencies": { - "@babel/core": "^7.14.6", - "@pmmmwh/react-refresh-webpack-plugin": "^0.5.7", - "@tarojs/cli": "3.5.3", - "@tarojs/plugin-mini-ci": "^3.5.3", - "@tarojs/plugin-react-devtools": "^3.5.3", - "@tarojs/webpack5-runner": "3.5.3", - "@types/react": "^18.0.0", - "@types/webpack-env": "^1.13.6", - "@typescript-eslint/eslint-plugin": "^5.20.0", - "@typescript-eslint/parser": "^5.20.0", - "babel-core": "^6.26.3", - "babel-eslint": "^10.1.0", - "babel-loader": "^8.1.0", - "babel-plugin-lodash": "^3.3.4", - "babel-plugin-transform-remove-console": "^6.9.4", - "babel-preset-env": "^1.7.0", - "babel-preset-taro": "3.5.3", - "eslint": "^8.12.0", - "eslint-config-prettier": "^6.10.1", - "eslint-config-taro": "3.5.3", - "eslint-plugin-import": "^2.23.4", - "eslint-plugin-prettier": "^3.4.0", - "eslint-plugin-react": "^7.24.0", - "eslint-plugin-react-hooks": "^4.2.0", - "lint-staged": "^7.2.2", - "lodash-webpack-plugin": "^0.11.5", - "miniprogram-api-typings": "^3.4.3", - "prettier": "^2.3.1", - "react-refresh": "^0.14.0", - "typescript": "^4.1.0", - "vconsole-webpack-plugin": "^1.6.1", - "webpack": "5.69.0", - "webpack-bundle-analyzer": "^3.3.2", - "stylelint": "^14.4.0" - }, - "lint-staged": { - "**/*.{ts,tsx,js,jsx,less}": [ - "prettier --write", - "git add" - ], - "**/*.{ts,tsx,js,jsx}": "npm run lint-staged:js" - } + "name": "tixwork-taro", + "version": "2.0.0", + "private": true, + "description": "rebuild from nice-router-taro", + "templateInfo": { + "name": "default", + "typescript": true, + "css": "Less", + "framework": "React" + }, + "scripts": { + "build:weapp": "taro build --type weapp", + "build:swan": "taro build --type swan", + "build:alipay": "taro build --type alipay", + "build:tt": "taro build --type tt", + "build:h5": "taro build --type h5", + "build:rn": "taro build --type rn", + "build:qq": "taro build --type qq", + "build:jd": "taro build --type jd", + "build:quickapp": "taro build --type quickapp", + "dev:weapp": "npm run build:weapp -- --watch", + "dev:swan": "npm run build:swan -- --watch", + "dev:alipay": "npm run build:alipay -- --watch", + "dev:tt": "npm run build:tt -- --watch", + "dev:h5": "npm run build:h5 -- --watch", + "dev:rn": "npm run build:rn -- --watch", + "dev:qq": "npm run build:qq -- --watch", + "dev:jd": "npm run build:jd -- --watch", + "dev:quickapp": "npm run build:quickapp -- --watch", + "test": "jest", + "format": "yarn prettier && yarn lint --fix", + "prettier": "prettier --write \"./src/**/*\" ", + "lint:fix": "eslint --fix --ext .js,.jsx,.ts,.tsx src", + "lint": "eslint --ext .js,.jsx,.ts,.tsx src", + "precommit": "lint-staged" + }, + "browserslist": [ + "last 3 versions", + "Android >= 4.1", + "ios >= 8" + ], + "author": "Kala ", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.21.5", + "@tarojs/components": "3.6.22", + "@tarojs/helper": "3.6.22", + "@tarojs/plugin-platform-weapp": "3.6.22", + "@tarojs/plugin-platform-alipay": "3.6.22", + "@tarojs/plugin-platform-tt": "3.6.22", + "@tarojs/plugin-platform-swan": "3.6.22", + "@tarojs/plugin-platform-jd": "3.6.22", + "@tarojs/plugin-platform-qq": "3.6.22", + "@tarojs/plugin-platform-h5": "3.6.22", + "@tarojs/runtime": "3.6.22", + "@tarojs/shared": "3.6.22", + "@tarojs/taro": "3.6.22", + "@tarojs/plugin-framework-react": "3.6.22", + "@tarojs/react": "3.6.22", + "react-dom": "^18.0.0", + "react": "^18.0.0", + "async-validator": "^3.5.2", + "classnames": "^2.3.1", + "crypto-es": "^1.2.7", + "global": "^4.4.0", + "jwt-decode": "^3.1.2", + "lodash": "^4.17.11", + "mime": "^2.5.2", + "nervjs": "^1.5.7", + "path-to-regexp": "^3.0.0", + "qr.js": "^0.0.0", + "vconsole": "^3.7.0" + }, + "devDependencies": { + "@babel/core": "^7.8.0", + "@tarojs/cli": "3.6.22", + "@types/webpack-env": "^1.13.6", + "@tarojs/test-utils-react": "^0.1.1", + "@types/react": "^18.0.0", + "webpack": "5.78.0", + "@tarojs/taro-loader": "3.6.22", + "@tarojs/webpack5-runner": "3.6.22", + "babel-preset-taro": "3.6.22", + "eslint-config-taro": "3.6.22", + "eslint": "^8.12.0", + "eslint-plugin-react": "^7.8.2", + "eslint-plugin-import": "^2.12.0", + "eslint-plugin-react-hooks": "^4.2.0", + "stylelint": "^14.4.0", + "@typescript-eslint/parser": "^6.2.0", + "@typescript-eslint/eslint-plugin": "^6.2.0", + "typescript": "5.1.6", + "tsconfig-paths-webpack-plugin": "^4.0.1", + "postcss": "^8.4.18", + "ts-node": "^10.9.1", + "@types/node": "^18.15.11", + "@types/jest": "^29.3.1", + "jest": "^29.3.1", + "jest-environment-jsdom": "^29.5.0", + "@pmmmwh/react-refresh-webpack-plugin": "^0.5.7", + "react-refresh": "^0.14.0", + "@tarojs/plugin-mini-ci": "3.6.22", + "@tarojs/plugin-react-devtools": "3.6.22", + "babel-core": "^6.26.3", + "babel-eslint": "^10.1.0", + "babel-loader": "^8.1.0", + "babel-plugin-lodash": "^3.3.4", + "babel-plugin-transform-remove-console": "^6.9.4", + "babel-preset-env": "^1.7.0", + "eslint-config-prettier": "^6.10.1", + "eslint-plugin-prettier": "^3.4.0", + "lint-staged": "^7.2.2", + "lodash-webpack-plugin": "^0.11.5", + "miniprogram-api-typings": "^3.4.3", + "prettier": "^2.3.1", + "vconsole-webpack-plugin": "^1.6.1", + "webpack-bundle-analyzer": "^3.3.2" + }, + "lint-staged": { + "**/*.{ts,tsx,js,jsx,less}": [ + "prettier --write", + "git add" + ], + "**/*.{ts,tsx,js,jsx}": "npm run lint-staged:js" + } } diff --git a/tixwork-taro/project.config.json b/tixwork-taro/project.config.json index 2493c5cb..af163d1f 100644 --- a/tixwork-taro/project.config.json +++ b/tixwork-taro/project.config.json @@ -4,53 +4,27 @@ "description": "tixwork-taro a wx development framework base on Taro and React", "appid": "wxd7ff628dc0e8870d", "setting": { - "urlCheck": false, + "urlCheck": true, "es6": false, "enhance": false, + "compileHotReLoad": false, "postcss": false, - "preloadBackgroundData": false, "minified": false, - "newFeature": true, - "coverView": true, - "nodeModules": false, - "autoAudits": false, - "showShadowRootInWxmlPanel": false, - "scopeDataCheck": false, - "uglifyFileName": false, - "checkInvalidKey": true, - "checkSiteMap": true, - "uploadWithSourceMap": true, - "compileHotReLoad": false, - "lazyloadPlaceholderEnable": false, - "useMultiFrameRuntime": true, - "useApiHook": true, - "useApiHostProcess": true, "babelSetting": { "ignore": [], "disablePlugins": [], "outputPath": "" }, - "enableEngineNative": false, - "useIsolateContext": true, - "userConfirmedBundleSwitch": false, - "packNpmManually": false, - "packNpmRelationList": [], - "minifyWXSS": true, - "disableUseStrict": false, - "minifyWXML": true, - "showES6CompileOption": false, - "useCompilerPlugins": false + "condition": false }, "compileType": "miniprogram", - "simulatorType": "wechat", - "libVersion": "2.25.2", - "simulatorPluginLibVersion": {}, - "condition": {}, + "libVersion": "3.3.0", "srcMiniprogramRoot": "dist/", "packOptions": { "ignore": [], "include": [] }, + "condition": {}, "editorSetting": { "tabIndent": "insertSpaces", "tabSize": 2 diff --git a/tixwork-taro/project.private.config.json b/tixwork-taro/project.private.config.json new file mode 100644 index 00000000..c78706f8 --- /dev/null +++ b/tixwork-taro/project.private.config.json @@ -0,0 +1,7 @@ +{ + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "projectname": "tixwork-taro", + "setting": { + "compileHotReLoad": true + } +} \ No newline at end of file diff --git a/tixwork-taro/project.tt.json b/tixwork-taro/project.tt.json index 4013c977..a1b6abe7 100644 --- a/tixwork-taro/project.tt.json +++ b/tixwork-taro/project.tt.json @@ -1,16 +1,9 @@ { - "setting": { - "urlCheck": true, - "es6": true, - "postcss": true, - "minified": true, - "newFeature": true - }, - "appid": "tt8ea1f81c1199734e", + "miniprogramRoot": "./", "projectname": "tixwork-taro", - "condition": { - "miniprogram": { - "current": -1 - } + "appid": "testAppId", + "setting": { + "es6": false, + "minified": false } } diff --git a/tixwork-taro/src/app.config.ts b/tixwork-taro/src/app.config.ts index b912ba31..1aaf0bf6 100644 --- a/tixwork-taro/src/app.config.ts +++ b/tixwork-taro/src/app.config.ts @@ -45,7 +45,7 @@ export default { window: { backgroundTextStyle: 'light', navigationBarBackgroundColor: '#28aaff', - navigationBarTitleText: '新都办事指南', + navigationBarTitleText: 'Tixwork', navigationBarTextStyle: 'white', enablePullDownRefresh: true, }, diff --git a/tixwork-taro/src/app.tsx b/tixwork-taro/src/app.tsx index cce74c81..a66c2e46 100644 --- a/tixwork-taro/src/app.tsx +++ b/tixwork-taro/src/app.tsx @@ -1,6 +1,6 @@ -import React from 'react'; +import { PropsWithChildren } from 'react'; import { isH5, isWeapp, noop } from '@/utils'; -import Taro from '@tarojs/taro'; +import Taro, { useLaunch } from '@tarojs/taro'; import { ModelProvider } from '@/model/model-provider'; import './app.less'; import TestData from './pages/mock-data/test-data'; @@ -21,60 +21,53 @@ if (isH5()) { Taro.useShareAppMessage = noop; } } - -class App extends React.Component { - componentDidMount() { - if (isWeapp()) { - this.updateWeapp(); - } - } - - updateWeapp = () => { - if (Taro.canIUse('getUpdateManager')) { - const updateManager = Taro.getUpdateManager(); - updateManager.onCheckForUpdate(() => { - console.log('checking app update .......'); - }); - updateManager.onUpdateReady(() => { - // noinspection JSIgnoredPromiseFromCall - Taro.showModal({ - title: '更新提示', - content: '新版本已经准备好,是否重启应用?', - success: function (res) { - if (res.confirm) { - updateManager.applyUpdate(); - } - }, - }); - }); - updateManager.onUpdateFailed(() => { - // noinspection JSIgnoredPromiseFromCall - Taro.showModal({ - title: '更新提示', - content: '新版本下载失败,请检查你的微信', - showCancel: false, - }); +const updateWeapp = () => { + if (Taro.canIUse('getUpdateManager')) { + const updateManager = Taro.getUpdateManager(); + updateManager.onCheckForUpdate(() => { + console.log('checking app update .......'); + }); + updateManager.onUpdateReady(() => { + // noinspection JSIgnoredPromiseFromCall + Taro.showModal({ + title: '更新提示', + content: '新版本已经准备好,是否重启应用?', + success: function(res) { + if (res.confirm) { + updateManager.applyUpdate(); + } + }, }); - } else { + }); + updateManager.onUpdateFailed(() => { // noinspection JSIgnoredPromiseFromCall Taro.showModal({ - title: '微信升级', - content: '当前微信版本过低,部分功能无法使用,请升级到最新版本', + title: '更新提示', + content: '新版本下载失败,请检查你的微信', showCancel: false, }); - } - }; - - // 在 App 类中的 render() 函数没有实际作用 - // 请勿修改此函数 - render() { - return ( - - {/*// @ts-ignore*/} - {this.props.children} - - ); + }); + } else { + // noinspection JSIgnoredPromiseFromCall + Taro.showModal({ + title: '微信升级', + content: '当前微信版本过低,部分功能无法使用,请升级到最新版本', + showCancel: false, + }); } +}; + +function App({ children }: PropsWithChildren) { + useLaunch(() => { + if (isWeapp()) { + updateWeapp(); + } + }); + return ( + + {children} + + ); } export default App; diff --git a/tixwork-taro/src/index.html b/tixwork-taro/src/index.html index 6137827c..36199bfd 100644 --- a/tixwork-taro/src/index.html +++ b/tixwork-taro/src/index.html @@ -8,7 +8,7 @@ - Nice Router Taro + Tixwork diff --git a/tixwork-taro/src/pages/home/home-page-backup.tsx b/tixwork-taro/src/pages/home/home-page-backup.tsx deleted file mode 100644 index 6191d832..00000000 --- a/tixwork-taro/src/pages/home/home-page-backup.tsx +++ /dev/null @@ -1,111 +0,0 @@ -// import Listof from '@/listof/listof'; -// import { useAjaxPullDown, usePageTitle } from '@/service/use-service'; -// import { View } from '@tarojs/components'; -// import { useSelector } from 'react-redux'; -// -// import './home.scss'; -// import ServerImage from '@/server-image/server-image'; -// import NavigationBox from '@/components/navigation/navigation-box'; -// import NavigationService from '@/nice-router/navigation-service'; -// import EleTabs from '@/components/elements/ele-tabs'; -// import ApiConfig from '@/utils/api-config'; -// import EleCarousel from '@/components/elements/ele-carousel'; -// -// const defaultList = [ -// { -// id: '10001', -// title: '申请成都市新都区产业人才奖励办事指南', -// brief: -// '从2017年1月1日后新引进我区企业工作的人才(不包括国有企业人才、企业化管理的事业单 位引进从业人才、企业内部调整调动进入的人才)可按规定申请补贴。', -// }, -// { -// id: '10002', -// title: '申请成都市新都区服务型制造平台补助奖励补助办事指南', -// brief: '经认定的国家、省、市服务型制造平翎号的服务型制造平台。\n2021-07-01', -// imageUrl: 'https://tiandtech.oss-cn-chengdu.aliyuncs.com/policy/policy-1.png', -// displayMode: 'big-card', -// }, -// { id: '10003', title: '申请成都市新都区服务型制造平台补助奖励补助办事指南', brief: '2021-07-01' }, -// ]; -// -// const ActionList = [ -// { -// id: '4', -// code: 'FINE_DECORATION', -// icon: 'icon_view', -// title: '我要查政策', -// onClick: () => { -// NavigationService.goPage('/pages/search/search-page', { search: '新都' }); -// }, -// }, -// { -// id: '3', -// code: 'BIZ_CHAIN', -// icon: 'bizfont-docs', -// title: '热门政策', -// onClick: () => { -// NavigationService.goPage('/pages/search/search-page', { search: '热门' }); -// }, -// }, -// ]; -// -// const defaultSlideList = [ -// { id: 1, imageUrl: 'https://tiandtech.oss-cn-chengdu.aliyuncs.com/policy/bg-1.jpg' }, -// { id: 1, imageUrl: 'https://tiandtech.oss-cn-chengdu.aliyuncs.com/policy/bg-2.jpg' }, -// { id: 1, imageUrl: 'https://tiandtech.oss-cn-chengdu.aliyuncs.com/policy/bg-3.jpg' }, -// ]; -// -// function HomePage(props) { -// // @ts-ignore -// const root = useSelector((state) => state.home); -// usePageTitle(root); -// useAjaxPullDown(props); -// -// const handleSearchClick = () => { -// NavigationService.goPage('/pages/search/search-page', { search: '热门政策' }); -// }; -// -// const { items = defaultList, slideList = defaultSlideList } = root; -// -// const handleItemClick = (item) => { -// NavigationService.goPage('/pages/policy/policy-detail-page', { id: item.id }); -// }; -// -// return ( -// -// -// -// -// 搜索 -// -// -// -// -// -// -// -// NavigationService.ajax(ApiConfig.FooterHome, { search: '新都' }), -// }, -// { -// title: '最新补贴', -// id: '2', -// onClick: () => NavigationService.ajax(ApiConfig.FooterHome, { search: '新都' }), -// }, -// ]} -// /> -// -// -// -// ); -// } -// -// export default HomePage; diff --git a/tixwork-taro/src/pages/home/home-page.config.ts b/tixwork-taro/src/pages/home/home-page.config.ts index 5a9f9a1a..fbfb18b1 100644 --- a/tixwork-taro/src/pages/home/home-page.config.ts +++ b/tixwork-taro/src/pages/home/home-page.config.ts @@ -1,4 +1,5 @@ -export default { +export default definePageConfig({ + navigationBarTitleText: '首页', enableShareTimeline: true, enableShareAppMessage: true, -}; +}); diff --git a/tixwork-taro/src/pages/home/home-page.tsx b/tixwork-taro/src/pages/home/home-page.tsx index 5265c032..01345f96 100644 --- a/tixwork-taro/src/pages/home/home-page.tsx +++ b/tixwork-taro/src/pages/home/home-page.tsx @@ -8,6 +8,7 @@ import useModel from '@/model/use-model'; import { CommonModel } from '@/model/models'; import { useEffect } from 'react'; import NavigationService from '@/nice-router/navigation-service'; +import { useLoad } from '@tarojs/taro'; import './home.less'; type HomeDataType = { @@ -17,6 +18,10 @@ type HomeDataType = { }; function HomePage(props) { + + useLoad(() => { + console.log('Page loaded.'); + }); const { root } = useModel>('home'); usePageTitle(root); @@ -52,12 +57,12 @@ function HomePage(props) { const { slideList = [], actionList = [], productList = [] } = root; return ( - - - + + + - - + + ); diff --git a/tixwork-taro/src/pages/search/search-page.tsx b/tixwork-taro/src/pages/search/search-page.tsx index a6d118db..7d8674b8 100644 --- a/tixwork-taro/src/pages/search/search-page.tsx +++ b/tixwork-taro/src/pages/search/search-page.tsx @@ -73,7 +73,7 @@ export default function SearchPage() { - + ); diff --git a/tixwork-taro/tsconfig.json b/tixwork-taro/tsconfig.json index f43e0b8c..28daacfc 100644 --- a/tixwork-taro/tsconfig.json +++ b/tixwork-taro/tsconfig.json @@ -1,6 +1,8 @@ { "compilerOptions": { - "types": ["miniprogram-api-typings"], + "types": [ + "miniprogram-api-typings" + ], "target": "es2017", "module": "commonjs", "removeComments": false, @@ -24,10 +26,17 @@ "global.d.ts" ], "paths": { - "@/*": ["./src/*"], + "@/*": [ + "./src/*" + ] } }, - "include": ["./src", "global.d.ts"], + "include": [ + "./src", + "./types", + "./config", + "global.d.ts" + ], "exclude": [ "node_modules", "dist" diff --git a/tixwork-taro/types/global.d.ts b/tixwork-taro/types/global.d.ts index 77121ba4..ad77965c 100644 --- a/tixwork-taro/types/global.d.ts +++ b/tixwork-taro/types/global.d.ts @@ -1,3 +1,5 @@ +/// + declare module '*.png'; declare module '*.gif'; declare module '*.jpg'; @@ -11,7 +13,17 @@ declare module '*.styl'; declare namespace NodeJS { interface ProcessEnv { + /** NODE 内置环境变量, 会影响到最终构建生成产物 */ + NODE_ENV: 'development' | 'production', + /** 当前构建的平台 */ TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd' + /** + * 当前构建的小程序 appid + * @description 若不同环境有不同的小程序,可通过在 env 文件中配置环境变量`TARO_APP_ID`来方便快速切换 appid, 而不必手动去修改 dist/project.config.json 文件 + * @see https://taro-docs.jd.com/docs/next/env-mode-config#特殊环境变量-taro_app_id + */ + TARO_APP_ID: string } } + diff --git a/tixwork-ui/.gitignore b/tixwork-ui/.gitignore index 7fd9f581..f8852e77 100644 --- a/tixwork-ui/.gitignore +++ b/tixwork-ui/.gitignore @@ -9,6 +9,7 @@ _roadhog-api-doc # production /dist /.vscode +dist # misc .DS_Store diff --git a/tixwork-ui/src/components/detail/group-box.tsx b/tixwork-ui/src/components/detail/group-box.tsx new file mode 100644 index 00000000..d30a55de --- /dev/null +++ b/tixwork-ui/src/components/detail/group-box.tsx @@ -0,0 +1,55 @@ +import BoxWrapper from '@/components/box-wrapper/box-wrapper'; +import { ProDescriptions } from '@ant-design/pro-components'; +import _ from 'lodash'; + +const isSingleLine = (type) => _.includes(['textarea', 'ObjectList'], type); + +/** + * 把textarea弄成单独的一行 + */ +const buildColumns = (columns) => { + let theColumn = columns.filter((it) => !it.hideInDescriptions).map((it) => ({ ...it, tooltip: '' })); + //1. 处理Id字段,在detail作为text + if (theColumn[0].dataIndex === 'id') { + theColumn = [{ ...theColumn[0], valueType: 'text' }].concat(theColumn.slice(1, theColumn.length)); + } + //2. + let globalPointer = 0; + return theColumn.map((it, idx) => { + // 2.1 本身是textarea + if (isSingleLine(it.valueType)) { + const result = { ...it, span: 3 }; + globalPointer = 0; + if (it.valueType === 'textarea') { + // ellipsis导致description ui有问题,临时在desc中干掉 + result.ellipsis = false; + // result.copyable = true; + } + return result; + } + + const next = theColumn[idx + 1]; + let span = 1; + if (next && isSingleLine(next.valueType)) { + span = 3 - globalPointer; + } + globalPointer = (globalPointer + 1) % 3; + return { ...it, span }; + }); +}; + +export default (props) => { + const { name, column, columns, dataSource } = props; + let theColumns = buildColumns(columns); + // const key = groupName + '_' + idx; + const showColumnLength = _.min([theColumns.length, column]); + if (theColumns.length === 1 && _.get(theColumns, '[0].title') === name) { + const col = theColumns[0]; + theColumns = [{ ...col, title: null }]; + } + return ( + + + + ); +}; diff --git a/tixwork-ui/src/components/detail/index.tsx b/tixwork-ui/src/components/detail/index.tsx index 6e72ec63..1100397e 100644 --- a/tixwork-ui/src/components/detail/index.tsx +++ b/tixwork-ui/src/components/detail/index.tsx @@ -1,6 +1,6 @@ import type { ResourceNameType } from '@/biz-models/biz-schema'; import BizSchema from '@/biz-models/biz-schema'; -import ObjectEntityInfo, { getObjectFieldProps } from '@/components/detail/object-entity-info'; +import ObjectEntityInfo from '@/components/detail/object-entity-info'; import type { ListItemsInfoType } from '@/components/detail/relative-entity-items'; import RelativeEntityItems from '@/components/detail/relative-entity-items'; import EleProProvider from '@/components/value-type/ele-pro-provider'; @@ -28,6 +28,26 @@ const defaultEmpty = ( ); + +const getObjectFieldProps = (props, parent) => { + const { dataIndex = 'id', title, fieldProps } = props; + const obj = _.get(parent, dataIndex); + const objectType = fieldProps?.objectType; + const columns = BizSchema.get(objectType)?.columns; + const result: ListItemsInfoType & { dataSource: any } = { + ...fieldProps, + parent, + editable: fieldProps.editable, + key: dataIndex, + dataSource: obj, + searchKey: fieldProps?.searchKey, + objectType, + columns, + title, + }; + return result; +}; + export default function EleDetail(props: EleDetailType) { const { objectType, className, dataSource, onRefresh, ...rest } = props; const schema = BizSchema.get(objectType); diff --git a/tixwork-ui/src/components/detail/object-entity-info.tsx b/tixwork-ui/src/components/detail/object-entity-info.tsx index 475d217f..98059d57 100644 --- a/tixwork-ui/src/components/detail/object-entity-info.tsx +++ b/tixwork-ui/src/components/detail/object-entity-info.tsx @@ -1,17 +1,15 @@ import type { ResourceNameType } from '@/biz-models/biz-schema'; -import BizSchema from '@/biz-models/biz-schema'; -import BoxWrapper from '@/components/box-wrapper/box-wrapper'; -import type { ListItemsInfoType } from '@/components/detail/relative-entity-items'; import ObjectLink from '@/components/value-type/object/object-link'; import { colors } from '@/components/value-type/style-utils'; import ObjectUtils from '@/utils/object-utils'; import { RightOutlined } from '@ant-design/icons'; import type { CardProps } from '@ant-design/pro-card/es/typing'; -import { ProCard, ProDescriptions } from '@ant-design/pro-components'; +import { ProCard } from '@ant-design/pro-components'; import { useEmotionCss } from '@ant-design/use-emotion-css'; import { Empty, Space } from 'antd'; import classNames from 'classnames'; import _ from 'lodash'; +import GroupBox from './group-box'; import styles from './styles.less'; type ObjectEntityInfoType = { @@ -43,60 +41,6 @@ const collapsibleIconRender = ({ collapsed }) => ( ); -const isSingleLine = (type) => _.includes(['textarea', 'ObjectList'], type); -/** - * 把textarea弄成单独的一行 - */ -const buildColumns = (columns) => { - let theColumn = columns.filter((it) => !it.hideInDescriptions).map((it) => ({ ...it, tooltip: '' })); - //1. 处理Id字段,在detail作为text - if (theColumn[0].dataIndex === 'id') { - theColumn = [{ ...theColumn[0], valueType: 'text' }].concat(theColumn.slice(1, theColumn.length)); - } - //2. - let globalPointer = 0; - return theColumn.map((it, idx) => { - // 2.1 本身是textarea - if (isSingleLine(it.valueType)) { - const result = { ...it, span: 3 }; - globalPointer = 0; - if (it.valueType === 'textarea') { - // ellipsis导致description ui有问题,临时在desc中干掉 - result.ellipsis = false; - // result.copyable = true; - } - return result; - } - - const next = theColumn[idx + 1]; - let span = 1; - if (next && isSingleLine(next.valueType)) { - span = 3 - globalPointer; - } - globalPointer = (globalPointer + 1) % 3; - return { ...it, span }; - }); -}; - -export const getObjectFieldProps = (props, parent) => { - const { dataIndex = 'id', title, fieldProps } = props; - const obj = _.get(parent, dataIndex); - const objectType = fieldProps?.objectType; - const columns = BizSchema.get(objectType)?.columns; - const result: ListItemsInfoType & { dataSource: any } = { - ...fieldProps, - parent, - editable: fieldProps.editable, - key: dataIndex, - dataSource: obj, - searchKey: fieldProps?.searchKey, - objectType, - columns, - title, - }; - return result; -}; - const ObjectEntityInfo = (props: ObjectEntityInfoType) => { const infoCss = useEmotionCss(({ token }) => ({ height: '100%', @@ -119,13 +63,14 @@ const ObjectEntityInfo = (props: ObjectEntityInfoType) => { const theColumns = columns.filter((it) => !it.hideInDescriptions); const grouped = _.groupBy(theColumns, (it) => { - if (ObjectUtils.isNotEmpty(it.group)) { - return it.group; + const isDefault = it.group === 'default'; + if (it.valueType === 'ObjectList' || it.valueType === 'RichText') { + return isDefault ? it.title : it.group; } if (it.valueType === 'Object') { - return '关联信息'; + return isDefault ? '关联信息' : it.group; } - return 'default'; + return it.group; }); // const grouped = _.groupBy(columns.filter((it) => it.valueType !== 'Object'), (it) => it.group ); @@ -140,16 +85,15 @@ const ObjectEntityInfo = (props: ObjectEntityInfoType) => { {...params} {...rest} > - {groupNames.map((groupName, idx) => { - const theColumn = buildColumns(grouped[groupName]); - const key = groupName + '_' + idx; - const showColumnLength = _.min([theColumn.length, column]); - return ( - - - - ); - })} + {groupNames.map((groupName, idx) => ( + + ))} {props.children} ); diff --git a/tixwork-ui/src/components/form/fields/clickable-item.tsx b/tixwork-ui/src/components/form/fields/clickable-item.tsx index cefba53e..a53ed8fd 100644 --- a/tixwork-ui/src/components/form/fields/clickable-item.tsx +++ b/tixwork-ui/src/components/form/fields/clickable-item.tsx @@ -5,6 +5,7 @@ import { CloseCircleFilled } from '@ant-design/icons'; import type { ProFormFieldProps } from '@ant-design/pro-components'; import { useEmotionCss } from '@ant-design/use-emotion-css'; import classNames from 'classnames'; +import _ from 'lodash'; type ClickableItemType = { value: any; @@ -12,7 +13,7 @@ type ClickableItemType = { onClick?: () => void; onClear?: () => void; className?: any; - placeholder?: string; + placeholder?: any; width?: ProFormFieldProps['width']; disabled?: boolean; allowClear?: boolean; @@ -50,11 +51,11 @@ export default function ClickableItem(props: ClickableItemType) { const title = showPlaceHolder ? placeholder : formatValue(value, itemRender); - const handleClick = () => { + const handleClick = _.debounce(() => { if (!disabled && onClick) { onClick(); } - }; + }, 200); const handleClear = () => { if (!disabled && onClear) { onClear(); diff --git a/tixwork-ui/src/components/form/remote/remote-select.tsx b/tixwork-ui/src/components/form/remote/remote-select.tsx index cb657363..f7b36ec0 100644 --- a/tixwork-ui/src/components/form/remote/remote-select.tsx +++ b/tixwork-ui/src/components/form/remote/remote-select.tsx @@ -68,7 +68,7 @@ export const _RemoteSelect = (props: RemoteSelectType) => { const RemoteSelect = (props) => { const { label, name, rules, labelCol, ...rest } = props; return ( - + <_RemoteSelect {...rest} /> ); diff --git a/tixwork-ui/src/components/layout/right-content/avatar-dropdown.tsx b/tixwork-ui/src/components/layout/right-content/avatar-dropdown.tsx index 0082a8e8..82bca73a 100644 --- a/tixwork-ui/src/components/layout/right-content/avatar-dropdown.tsx +++ b/tixwork-ui/src/components/layout/right-content/avatar-dropdown.tsx @@ -28,6 +28,7 @@ export default function AvatarDropdown() { transition: 'all 0.3s', fontWeight: 500, color: token.colorTextHeading, + minWidth: 100, '.ant-avatar': { marginRight: 8, diff --git a/tixwork-ui/src/components/split-card/styles.less b/tixwork-ui/src/components/split-card/styles.less index 292cdaac..ee09a29e 100644 --- a/tixwork-ui/src/components/split-card/styles.less +++ b/tixwork-ui/src/components/split-card/styles.less @@ -117,5 +117,6 @@ } .expanded .left { + height: 0; padding-right: 12px; } diff --git a/tixwork-ui/src/components/value-type/index.tsx b/tixwork-ui/src/components/value-type/index.tsx index 6ef02166..17332440 100644 --- a/tixwork-ui/src/components/value-type/index.tsx +++ b/tixwork-ui/src/components/value-type/index.tsx @@ -13,10 +13,10 @@ import { ImageListValueType, SingleImageValueType, } from '@/components/value-type/file'; -import { RichEditorValueType } from '@/components/value-type/rich-editor'; import { ObjectValueType } from './object/object-link'; import { ObjectListValueType } from './object/object-list'; import { RemoteCascadeValueType, RemoteEnumValueType, RemoteRadioValueType, RemoteSelectValueType } from './remote'; +import { RichTextValueType } from './rich-text'; type PartialRecord = { [P in K]?: T }; export type BizColumnType = { group?: string } & ProColumnType; @@ -39,7 +39,7 @@ export type CustomerValueType = | 'RemoteEnum' | 'RemoteSelect' | 'Uid' - | 'RichEdit' + | 'RichText' | 'File' | 'FileList' | 'RemoteCascade'; @@ -66,7 +66,7 @@ const elements: PartialRecord = { RemoteEnum: RemoteEnumValueType, RemoteSelect: RemoteSelectValueType, RemoteCascade: RemoteCascadeValueType, - RichEdit: RichEditorValueType, + RichText: RichTextValueType, }; export default elements; diff --git a/tixwork-ui/src/components/value-type/object/object-link.tsx b/tixwork-ui/src/components/value-type/object/object-link.tsx index 2928e3f3..28595749 100644 --- a/tixwork-ui/src/components/value-type/object/object-link.tsx +++ b/tixwork-ui/src/components/value-type/object/object-link.tsx @@ -12,7 +12,6 @@ import { LinkOutlined } from '@ant-design/icons'; import { ProCard } from '@ant-design/pro-components'; import { useEmotionCss } from '@ant-design/use-emotion-css'; import classNames from 'classnames'; -import styles from './styles.less'; type ObjectLinkType = { id?: React.Key; @@ -59,9 +58,15 @@ const InnerLink = (props) => { const linkToUrl = getLinkToUrl(props) as string; const { displayName, record = {}, className } = props; const title = displayName || getDisplayName(record); - const rootCls = classNames(className, { - [styles.objectLink]: ObjectUtils.isNotEmpty(linkToUrl), - }); + const css = useEmotionCss(({ token }) => ({ + color: token.colorPrimary, + fontWeight: 500, + cursor: 'pointer !important', + '&:hover': { + color: '#f38709 !important', + }, + })); + const rootCls = classNames('object-link', className, ObjectUtils.isNotEmpty(linkToUrl) && css); return ( {title} @@ -71,6 +76,16 @@ const InnerLink = (props) => { const PopupContent = (props) => { const { displayName, objectType, record = {} } = props; + const css = useEmotionCss(() => ({ + ':first-child.group-card': { + padding: 0, + border: 'none', + }, + '.ant-pro-card-body': { + padding: '10px 0 0', + }, + })); + const title = displayName || getDisplayName(record); const schema = BizSchema.get(objectType); const columns = (schema?.columns || []).filter((it) => it.valueType !== 'Object'); @@ -98,7 +113,7 @@ const PopupContent = (props) => { padding: 0, paddingBottom: 10, }} - className={styles.objectLinkPopupContent} + className={css} > @@ -126,6 +141,7 @@ const ObjectLink = (props: ObjectLinkType) => { ); }; + export function renderObject(item, props) { const { fieldProps } = props; const obj = _.isObject(item) ? item : ({ displayName: item } as any); diff --git a/tixwork-ui/src/components/value-type/object/object-list-picker.tsx b/tixwork-ui/src/components/value-type/object/object-list-picker.tsx index 14379669..cd31fbc3 100644 --- a/tixwork-ui/src/components/value-type/object/object-list-picker.tsx +++ b/tixwork-ui/src/components/value-type/object/object-list-picker.tsx @@ -1,18 +1,25 @@ import ObjectUtils from '@/utils/object-utils'; import { PlusOutlined } from '@ant-design/icons'; import { ProFormItem } from '@ant-design/pro-components'; +import { useEmotionCss } from '@ant-design/use-emotion-css'; import { Typography } from 'antd'; import _ from 'lodash'; import { ObjectListTable } from './object-list-table'; import type { ObjectPickerType } from './object-picker'; import type { ObjectPickerFieldType } from './object-picker-field'; import ObjectPickerField from './object-picker-field'; -import styles from './styles.less'; const LinkTarget = (props) => { const { onClick, disabled } = props; + const css = useEmotionCss(() => ({ + display: 'flex', + flexDirection: 'row-reverse', + width: ' 100%', + marginTop: -28, + paddingBottom: 6, + })); return ( -
+
添加 diff --git a/tixwork-ui/src/components/value-type/object/styles.less b/tixwork-ui/src/components/value-type/object/styles.less deleted file mode 100644 index 16d2c9f2..00000000 --- a/tixwork-ui/src/components/value-type/object/styles.less +++ /dev/null @@ -1,39 +0,0 @@ -/* @import '~antd/es/style/themes/default.less'; */ - -.objectLink { - color: @primary-color; - font-weight: 500; - cursor: pointer; - - &:hover { - color: #f38709 !important; - } -} - -.objectLinkPopupContent { - :global(:first-child.group-card) { - padding: 0; - border: none; - } - - :global(.ant-pro-card-body) { - padding: 10px 0 0; - } -} - -.objectPicker { - :global { - .ant-form-item, - .pro-field { - margin-bottom: 0; - } - } -} - -.linkTarget { - display: flex; - flex-direction: row-reverse; - width: 100%; - margin-top: -28px; - padding-bottom: 6px; -} diff --git a/tixwork-ui/src/components/value-type/rich-editor/index.tsx b/tixwork-ui/src/components/value-type/rich-text/index.tsx similarity index 82% rename from tixwork-ui/src/components/value-type/rich-editor/index.tsx rename to tixwork-ui/src/components/value-type/rich-text/index.tsx index d8023855..5433e620 100644 --- a/tixwork-ui/src/components/value-type/rich-editor/index.tsx +++ b/tixwork-ui/src/components/value-type/rich-text/index.tsx @@ -1,4 +1,4 @@ -import RichEditor, { RichEditorType } from '@/components/value-type/rich-editor/rich-editor'; +import RichEditor, { RichEditorType } from '@/components/value-type/rich-text/rich-editor'; import { ProFormField, ProFormFieldProps } from '@ant-design/pro-components'; export default function ProFormRichEditor(props: RichEditorType & Partial) { @@ -11,7 +11,7 @@ export default function ProFormRichEditor(props: RichEditorType & Partial ); } -export const RichEditorValueType = { - render: (text) => , +export const RichTextValueType = { + render: (dom) => , renderFormItem: (__, props) => , }; diff --git a/tixwork-ui/src/components/value-type/rich-editor/rich-editor.tsx b/tixwork-ui/src/components/value-type/rich-text/rich-editor.tsx similarity index 94% rename from tixwork-ui/src/components/value-type/rich-editor/rich-editor.tsx rename to tixwork-ui/src/components/value-type/rich-text/rich-editor.tsx index 6ce318e8..7a8ff900 100644 --- a/tixwork-ui/src/components/value-type/rich-editor/rich-editor.tsx +++ b/tixwork-ui/src/components/value-type/rich-text/rich-editor.tsx @@ -19,6 +19,7 @@ export default function RichEditor(props: RichEditorType) { const [content, setContent] = useState(value ?? ''); useEffect(() => { + console.log('vvvvvvvv', value); setContent(value ?? ''); }, [value]); @@ -29,9 +30,10 @@ export default function RichEditor(props: RichEditorType) { } onChange?.(html); }; + const rootClz = classNames('rich-editor', className); return ( -
+
{ export default function DetailRoleMenu(props) { const { message } = App.useApp(); const { hideLoading, showLoading, loading } = useLoading(); - const [menuState, setMenuState] = useState>({}); + const [menuState, setMenuState] = useState>({}); const { role } = props; diff --git a/tixwork-ui/src/pages/tenant/package/package-menu.tsx b/tixwork-ui/src/pages/tenant/package/package-menu.tsx index 7a86924c..9a25829f 100644 --- a/tixwork-ui/src/pages/tenant/package/package-menu.tsx +++ b/tixwork-ui/src/pages/tenant/package/package-menu.tsx @@ -31,7 +31,7 @@ const getCheckedList = (menu: API.Menu, checkedList: React.Key[]) => { export default (props: API.TenantPackage) => { const { message } = App.useApp(); const { hideLoading, showLoading, loading } = useLoading(); - const [menuState, setMenuState] = useState>({}); + const [menuState, setMenuState] = useState>({}); const { id, menuIds } = props; diff --git a/tixwork-ui/src/pages/tts/dist/index.cjs.js b/tixwork-ui/src/pages/tts/dist/index.cjs.js deleted file mode 100755 index 9ca3ea66..00000000 --- a/tixwork-ui/src/pages/tts/dist/index.cjs.js +++ /dev/null @@ -1,174 +0,0 @@ -'use strict'; -function t(t, a, i) { - for (var o = 0; o < i.length; o++) t.setUint8(a + o, i.charCodeAt(o)); -} -function a(a, i, o) { - var e = (function (a, i, o, e, s) { - var u = a.reduce(function (t, a) { - return t + a.byteLength; - }, 0), - n = new ArrayBuffer(44 + u), - r = new DataView(n), - h = o, - d = 0; - return ( - t(r, d, 'RIFF'), - (d += 4), - r.setUint32(d, 36 + u, !0), - t(r, (d += 4), 'WAVE'), - t(r, (d += 4), 'fmt '), - (d += 4), - r.setUint32(d, 16, !0), - (d += 4), - r.setUint16(d, 1, !0), - (d += 2), - r.setUint16(d, h, !0), - (d += 2), - r.setUint32(d, i, !0), - (d += 4), - r.setUint32(d, h * i * (e / 8), !0), - (d += 4), - r.setUint16(d, h * (e / 8), !0), - (d += 2), - r.setUint16(d, e, !0), - t(r, (d += 2), 'data'), - (d += 4), - r.setUint32(d, u, !0), - (d += 4), - a.forEach(function (t) { - for (var a = new DataView(t.buffer), i = 0; i < t.byteLength; ) r.setUint8(d, a.getUint8(i)), d++, i++; - }), - r - ); - })(a, i || 16e3, 1, o || 16); - return new Blob([e], { type: 'audio/wav' }); -} -var i = (function () { - function t(t) { - (this.toSampleRate = 22050), - (this.resumePlayDuration = 1e3), - (this.fromSampleRate = 16e3), - (this.isAudioDataEnded = !1), - (this.status = 'uninit'), - (this.audioDatas = []), - (this.pcmAudioDatas = []), - (this.audioDataOffset = 0), - (this.processor = new Worker(''.concat(t, '/processor.worker.js'))); - } - return ( - (t.prototype.postMessage = function (t) { - var a = t.type, - i = t.data, - o = t.isLastData; - 'uninit' !== this.status && (this.processor.postMessage({ type: a, data: i }), (this.isAudioDataEnded = o)); - }), - (t.prototype.playAudio = function () { - var t = this; - if ((clearTimeout(this.playAudioTime), this.audioContext)) { - for (var a = 0, i = this.audioDataOffset; i < this.audioDatas.length; i++) a += this.audioDatas[i].length; - if (!a) - return void ( - 'play' === this.status && - (this.isAudioDataEnded || this.resumePlayDuration <= 0 - ? this.stop() - : (this.playAudioTime = setTimeout(function () { - t.playAudio(); - }, this.resumePlayDuration))) - ); - for ( - var o = this.audioContext.createBuffer(1, a, this.toSampleRate), - e = o.getChannelData(0), - s = this.audioDatas[this.audioDataOffset], - u = 0; - s; - - ) { - if (((this.audioDataOffset += 1), o.copyToChannel)) o.copyToChannel(s, 0, u), (u += s.length); - else for (i = 0; i < s.length; i++) e[i] = s[i]; - s = this.audioDatas[this.audioDataOffset]; - } - var n = this.audioContext.createBufferSource(); - (this.bufferSource = n), - (n.buffer = o), - n.connect(this.audioContext.destination), - n.start(), - (n.onended = function (a) { - 'play' === t.status && - (t.audioDatas.length - ? t.playAudio() - : t.isAudioDataEnded || t.resumePlayDuration <= 0 - ? t.stop() - : (t.playAudioTime = setTimeout(function () { - t.playAudio(); - }, t.resumePlayDuration))); - }); - } - }), - (t.prototype.reset = function () { - var t; - (this.processor.onmessage = null), - (this.audioDataOffset = 0), - (this.audioDatas = []), - (this.pcmAudioDatas = []), - (this.status = 'uninit'), - (this.isAudioDataEnded = !1), - clearTimeout(this.playAudioTime); - try { - null === (t = this.bufferSource) || void 0 === t || t.stop(); - } catch (t) { - console.log(t); - } - }), - (t.prototype.start = function (t) { - var a = this, - i = void 0 === t ? {} : t, - o = i.autoPlay, - e = void 0 === o || o, - s = i.sampleRate, - u = void 0 === s ? 16e3 : s, - n = i.resumePlayDuration, - r = void 0 === n ? 1e3 : n; - this.reset(), (this.status = 'init'), (this.resumePlayDuration = r); - var h = u, - d = Math.max(h, 22050); - (d = Math.min(d, 96e3)), - (this.fromSampleRate = h), - (this.toSampleRate = d), - this.processor.postMessage({ type: 'init', data: { fromSampleRate: h, toSampleRate: d } }), - (this.processor.onmessage = function (t) { - var i = t.data, - o = i.audioData, - s = i.pcmAudioData; - a.audioDatas.push(o), - a.pcmAudioDatas.push(s), - 1 === a.audioDatas.length && e && 'init' === a.status && a.play(); - }); - }), - (t.prototype.play = function () { - var t; - this.audioContext || - ((this.audioContext = new (window.AudioContext || window.webkitAudioContext)()), this.audioContext.resume()), - this.audioContext && - ((this.status = 'play'), null === (t = this.onPlay) || void 0 === t || t.call(this), this.playAudio()); - }), - (t.prototype.stop = function () { - var t, a; - (this.audioDataOffset = 0), (this.status = 'stop'), clearTimeout(this.playAudioTime); - try { - null === (t = this.bufferSource) || void 0 === t || t.stop(), - null === (a = this.onStop) || void 0 === a || a.call(this, this.audioDatas); - } catch (t) { - console.log(t); - } - }), - (t.prototype.getAudioDataBlob = function (t) { - var i, o; - if (null === (i = this.pcmAudioDatas) || void 0 === i ? void 0 : i.length) - return 'wav' === t - ? a(this.pcmAudioDatas, this.fromSampleRate, 16) - : ((o = this.pcmAudioDatas), new Blob(o, { type: 'audio/pcm' })); - }), - t - ); -})(); -module.exports = i; diff --git a/tixwork-ui/src/pages/tts/dist/index.d.ts b/tixwork-ui/src/pages/tts/dist/index.d.ts deleted file mode 100755 index 78d526ca..00000000 --- a/tixwork-ui/src/pages/tts/dist/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -type ISaveAudioData = 'pcm' | 'wav'; -declare class AudioPlayer { - constructor(processorPath?: string); - private toSampleRate; - private resumePlayDuration; - private fromSampleRate; - private isAudioDataEnded; - private playAudioTime?; - private status; - private audioContext?; - private bufferSource?; - private audioDatas; - private pcmAudioDatas; - private audioDataOffset; - private processor; - postMessage({ - type, - data, - isLastData, - }: { - type: 'base64' | 'string' | 'Int16Array' | 'Float32Array'; - data: string | Int16Array | Float32Array; - isLastData: boolean; - }): void; - private onPlay?; - private onStop?; - private playAudio; - reset(): void; - start({ - autoPlay, - sampleRate, - resumePlayDuration, - }?: { - autoPlay?: boolean; - sampleRate?: number; - resumePlayDuration?: number; - }): void; - play(): void; - stop(): void; - getAudioDataBlob(type: ISaveAudioData): Blob | undefined; -} - -export { AudioPlayer as default }; diff --git a/tixwork-ui/src/pages/tts/dist/index.esm.js b/tixwork-ui/src/pages/tts/dist/index.esm.js deleted file mode 100755 index 0c017ba5..00000000 --- a/tixwork-ui/src/pages/tts/dist/index.esm.js +++ /dev/null @@ -1,173 +0,0 @@ -function t(t, a, i) { - for (var o = 0; o < i.length; o++) t.setUint8(a + o, i.charCodeAt(o)); -} -function a(a, i, o) { - var e = (function (a, i, o, e, s) { - var u = a.reduce(function (t, a) { - return t + a.byteLength; - }, 0), - n = new ArrayBuffer(44 + u), - r = new DataView(n), - h = o, - d = 0; - return ( - t(r, d, 'RIFF'), - (d += 4), - r.setUint32(d, 36 + u, !0), - t(r, (d += 4), 'WAVE'), - t(r, (d += 4), 'fmt '), - (d += 4), - r.setUint32(d, 16, !0), - (d += 4), - r.setUint16(d, 1, !0), - (d += 2), - r.setUint16(d, h, !0), - (d += 2), - r.setUint32(d, i, !0), - (d += 4), - r.setUint32(d, h * i * (e / 8), !0), - (d += 4), - r.setUint16(d, h * (e / 8), !0), - (d += 2), - r.setUint16(d, e, !0), - t(r, (d += 2), 'data'), - (d += 4), - r.setUint32(d, u, !0), - (d += 4), - a.forEach(function (t) { - for (var a = new DataView(t.buffer), i = 0; i < t.byteLength; ) r.setUint8(d, a.getUint8(i)), d++, i++; - }), - r - ); - })(a, i || 16e3, 1, o || 16); - return new Blob([e], { type: 'audio/wav' }); -} -var i = (function () { - function t(t) { - (this.toSampleRate = 22050), - (this.resumePlayDuration = 1e3), - (this.fromSampleRate = 16e3), - (this.isAudioDataEnded = !1), - (this.status = 'uninit'), - (this.audioDatas = []), - (this.pcmAudioDatas = []), - (this.audioDataOffset = 0), - (this.processor = new Worker(''.concat(t, '/processor.worker.js'))); - } - return ( - (t.prototype.postMessage = function (t) { - var a = t.type, - i = t.data, - o = t.isLastData; - 'uninit' !== this.status && (this.processor.postMessage({ type: a, data: i }), (this.isAudioDataEnded = o)); - }), - (t.prototype.playAudio = function () { - var t = this; - if ((clearTimeout(this.playAudioTime), this.audioContext)) { - for (var a = 0, i = this.audioDataOffset; i < this.audioDatas.length; i++) a += this.audioDatas[i].length; - if (!a) - return void ( - 'play' === this.status && - (this.isAudioDataEnded || this.resumePlayDuration <= 0 - ? this.stop() - : (this.playAudioTime = setTimeout(function () { - t.playAudio(); - }, this.resumePlayDuration))) - ); - for ( - var o = this.audioContext.createBuffer(1, a, this.toSampleRate), - e = o.getChannelData(0), - s = this.audioDatas[this.audioDataOffset], - u = 0; - s; - - ) { - if (((this.audioDataOffset += 1), o.copyToChannel)) o.copyToChannel(s, 0, u), (u += s.length); - else for (i = 0; i < s.length; i++) e[i] = s[i]; - s = this.audioDatas[this.audioDataOffset]; - } - var n = this.audioContext.createBufferSource(); - (this.bufferSource = n), - (n.buffer = o), - n.connect(this.audioContext.destination), - n.start(), - (n.onended = function (a) { - 'play' === t.status && - (t.audioDatas.length - ? t.playAudio() - : t.isAudioDataEnded || t.resumePlayDuration <= 0 - ? t.stop() - : (t.playAudioTime = setTimeout(function () { - t.playAudio(); - }, t.resumePlayDuration))); - }); - } - }), - (t.prototype.reset = function () { - var t; - (this.processor.onmessage = null), - (this.audioDataOffset = 0), - (this.audioDatas = []), - (this.pcmAudioDatas = []), - (this.status = 'uninit'), - (this.isAudioDataEnded = !1), - clearTimeout(this.playAudioTime); - try { - null === (t = this.bufferSource) || void 0 === t || t.stop(); - } catch (t) { - console.log(t); - } - }), - (t.prototype.start = function (t) { - var a = this, - i = void 0 === t ? {} : t, - o = i.autoPlay, - e = void 0 === o || o, - s = i.sampleRate, - u = void 0 === s ? 16e3 : s, - n = i.resumePlayDuration, - r = void 0 === n ? 1e3 : n; - this.reset(), (this.status = 'init'), (this.resumePlayDuration = r); - var h = u, - d = Math.max(h, 22050); - (d = Math.min(d, 96e3)), - (this.fromSampleRate = h), - (this.toSampleRate = d), - this.processor.postMessage({ type: 'init', data: { fromSampleRate: h, toSampleRate: d } }), - (this.processor.onmessage = function (t) { - var i = t.data, - o = i.audioData, - s = i.pcmAudioData; - a.audioDatas.push(o), - a.pcmAudioDatas.push(s), - 1 === a.audioDatas.length && e && 'init' === a.status && a.play(); - }); - }), - (t.prototype.play = function () { - var t; - this.audioContext || - ((this.audioContext = new (window.AudioContext || window.webkitAudioContext)()), this.audioContext.resume()), - this.audioContext && - ((this.status = 'play'), null === (t = this.onPlay) || void 0 === t || t.call(this), this.playAudio()); - }), - (t.prototype.stop = function () { - var t, a; - (this.audioDataOffset = 0), (this.status = 'stop'), clearTimeout(this.playAudioTime); - try { - null === (t = this.bufferSource) || void 0 === t || t.stop(), - null === (a = this.onStop) || void 0 === a || a.call(this, this.audioDatas); - } catch (t) { - console.log(t); - } - }), - (t.prototype.getAudioDataBlob = function (t) { - var i, o; - if (null === (i = this.pcmAudioDatas) || void 0 === i ? void 0 : i.length) - return 'wav' === t - ? a(this.pcmAudioDatas, this.fromSampleRate, 16) - : ((o = this.pcmAudioDatas), new Blob(o, { type: 'audio/pcm' })); - }), - t - ); -})(); -export { i as default }; diff --git a/tixwork-ui/src/pages/tts/dist/index.umd.js b/tixwork-ui/src/pages/tts/dist/index.umd.js deleted file mode 100755 index 76a54ad8..00000000 --- a/tixwork-ui/src/pages/tts/dist/index.umd.js +++ /dev/null @@ -1,181 +0,0 @@ -!(function (t, i) { - 'object' == typeof exports && 'undefined' != typeof module - ? (module.exports = i()) - : 'function' == typeof define && define.amd - ? define(i) - : ((t = 'undefined' != typeof globalThis ? globalThis : t || self).AudioPlayer = i()); -})(this, function () { - 'use strict'; - function t(t, i, a) { - for (var e = 0; e < a.length; e++) t.setUint8(i + e, a.charCodeAt(e)); - } - function i(i, a, e) { - var o = (function (i, a, e, o, s) { - var n = i.reduce(function (t, i) { - return t + i.byteLength; - }, 0), - u = new ArrayBuffer(44 + n), - r = new DataView(u), - d = e, - h = 0; - return ( - t(r, h, 'RIFF'), - (h += 4), - r.setUint32(h, 36 + n, !0), - t(r, (h += 4), 'WAVE'), - t(r, (h += 4), 'fmt '), - (h += 4), - r.setUint32(h, 16, !0), - (h += 4), - r.setUint16(h, 1, !0), - (h += 2), - r.setUint16(h, d, !0), - (h += 2), - r.setUint32(h, a, !0), - (h += 4), - r.setUint32(h, d * a * (o / 8), !0), - (h += 4), - r.setUint16(h, d * (o / 8), !0), - (h += 2), - r.setUint16(h, o, !0), - t(r, (h += 2), 'data'), - (h += 4), - r.setUint32(h, n, !0), - (h += 4), - i.forEach(function (t) { - for (var i = new DataView(t.buffer), a = 0; a < t.byteLength; ) r.setUint8(h, i.getUint8(a)), h++, a++; - }), - r - ); - })(i, a || 16e3, 1, e || 16); - return new Blob([o], { type: 'audio/wav' }); - } - return (function () { - function t(t) { - (this.toSampleRate = 22050), - (this.resumePlayDuration = 1e3), - (this.fromSampleRate = 16e3), - (this.isAudioDataEnded = !1), - (this.status = 'uninit'), - (this.audioDatas = []), - (this.pcmAudioDatas = []), - (this.audioDataOffset = 0), - (this.processor = new Worker(''.concat(t, '/processor.worker.js'))); - } - return ( - (t.prototype.postMessage = function (t) { - var i = t.type, - a = t.data, - e = t.isLastData; - 'uninit' !== this.status && (this.processor.postMessage({ type: i, data: a }), (this.isAudioDataEnded = e)); - }), - (t.prototype.playAudio = function () { - var t = this; - if ((clearTimeout(this.playAudioTime), this.audioContext)) { - for (var i = 0, a = this.audioDataOffset; a < this.audioDatas.length; a++) i += this.audioDatas[a].length; - if (!i) - return void ( - 'play' === this.status && - (this.isAudioDataEnded || this.resumePlayDuration <= 0 - ? this.stop() - : (this.playAudioTime = setTimeout(function () { - t.playAudio(); - }, this.resumePlayDuration))) - ); - for ( - var e = this.audioContext.createBuffer(1, i, this.toSampleRate), - o = e.getChannelData(0), - s = this.audioDatas[this.audioDataOffset], - n = 0; - s; - - ) { - if (((this.audioDataOffset += 1), e.copyToChannel)) e.copyToChannel(s, 0, n), (n += s.length); - else for (a = 0; a < s.length; a++) o[a] = s[a]; - s = this.audioDatas[this.audioDataOffset]; - } - var u = this.audioContext.createBufferSource(); - (this.bufferSource = u), - (u.buffer = e), - u.connect(this.audioContext.destination), - u.start(), - (u.onended = function (i) { - 'play' === t.status && - (t.audioDatas.length - ? t.playAudio() - : t.isAudioDataEnded || t.resumePlayDuration <= 0 - ? t.stop() - : (t.playAudioTime = setTimeout(function () { - t.playAudio(); - }, t.resumePlayDuration))); - }); - } - }), - (t.prototype.reset = function () { - var t; - (this.processor.onmessage = null), - (this.audioDataOffset = 0), - (this.audioDatas = []), - (this.pcmAudioDatas = []), - (this.status = 'uninit'), - (this.isAudioDataEnded = !1), - clearTimeout(this.playAudioTime); - try { - null === (t = this.bufferSource) || void 0 === t || t.stop(); - } catch (t) { - console.log(t); - } - }), - (t.prototype.start = function (t) { - var i = this, - a = void 0 === t ? {} : t, - e = a.autoPlay, - o = void 0 === e || e, - s = a.sampleRate, - n = void 0 === s ? 16e3 : s, - u = a.resumePlayDuration, - r = void 0 === u ? 1e3 : u; - this.reset(), (this.status = 'init'), (this.resumePlayDuration = r); - var d = n, - h = Math.max(d, 22050); - (h = Math.min(h, 96e3)), - (this.fromSampleRate = d), - (this.toSampleRate = h), - this.processor.postMessage({ type: 'init', data: { fromSampleRate: d, toSampleRate: h } }), - (this.processor.onmessage = function (t) { - var a = t.data, - e = a.audioData, - s = a.pcmAudioData; - i.audioDatas.push(e), - i.pcmAudioDatas.push(s), - 1 === i.audioDatas.length && o && 'init' === i.status && i.play(); - }); - }), - (t.prototype.play = function () { - var t; - this.audioContext || - ((this.audioContext = new (window.AudioContext || window.webkitAudioContext)()), this.audioContext.resume()), - this.audioContext && - ((this.status = 'play'), null === (t = this.onPlay) || void 0 === t || t.call(this), this.playAudio()); - }), - (t.prototype.stop = function () { - var t, i; - (this.audioDataOffset = 0), (this.status = 'stop'), clearTimeout(this.playAudioTime); - try { - null === (t = this.bufferSource) || void 0 === t || t.stop(), - null === (i = this.onStop) || void 0 === i || i.call(this, this.audioDatas); - } catch (t) { - console.log(t); - } - }), - (t.prototype.getAudioDataBlob = function (t) { - var a, e; - if (null === (a = this.pcmAudioDatas) || void 0 === a ? void 0 : a.length) - return 'wav' === t - ? i(this.pcmAudioDatas, this.fromSampleRate, 16) - : ((e = this.pcmAudioDatas), new Blob(e, { type: 'audio/pcm' })); - }), - t - ); - })(); -}); diff --git a/tixwork-ui/src/pages/tts/dist/processor.worker.js b/tixwork-ui/src/pages/tts/dist/processor.worker.js deleted file mode 100755 index 77b2d5b4..00000000 --- a/tixwork-ui/src/pages/tts/dist/processor.worker.js +++ /dev/null @@ -1,42 +0,0 @@ -!(function () { - 'use strict'; - self.onmessage = function (a) { - var t = a.data, - e = t.type, - r = t.data, - o = r; - if ('init' === e) { - var n = r.fromSampleRate, - l = r.toSampleRate; - return (self.fromSampleRate = n), void (self.toSampleRate = l); - } - if (('base64' === e && (o = atob(r)), 'string' == typeof o)) { - for (var f = new Uint8Array(o.length + (o.length % 2)), i = 0; i < o.length; ++i) f[i] = o.charCodeAt(i); - o = new Int16Array(f.buffer); - } - var s = o; - 'Float32Array' !== e && - (o = (function (a) { - for (var t = [], e = 0; e < a.length; e++) { - var r = a[e] < 0 ? a[e] / 32768 : a[e] / 32767; - t.push(r); - } - return new Float32Array(t); - })(o)), - (o = (function (a, t, e) { - var r = Math.round(a.length * (e / t)), - o = new Float32Array(r), - n = (a.length - 1) / (r - 1); - o[0] = a[0]; - for (var l = 1; l < r - 1; l++) { - var f = l * n, - i = Math.floor(f).toFixed(), - s = Math.ceil(f).toFixed(), - u = f - i; - o[l] = a[i] + (a[s] - a[i]) * u; - } - return (o[r - 1] = a[a.length - 1]), o; - })(o, self.fromSampleRate, self.toSampleRate)), - self.postMessage({ audioData: o, pcmAudioData: s }); - }; -})();