diff --git a/playgrounds/react/babel.config.js b/playgrounds/react/babel.config.js index f3acb81..f0f4486 100644 --- a/playgrounds/react/babel.config.js +++ b/playgrounds/react/babel.config.js @@ -4,7 +4,7 @@ module.exports = { presets: [ ['taro', { framework: 'react', - ts: true - }] - ] + ts: true, + }], + ], } diff --git a/playgrounds/react/config/dev.js b/playgrounds/react/config/dev.js index 6821bf8..aa91fd1 100644 --- a/playgrounds/react/config/dev.js +++ b/playgrounds/react/config/dev.js @@ -1,9 +1,9 @@ module.exports = { env: { - NODE_ENV: '"development"' + NODE_ENV: '"development"', }, defineConstants: { }, mini: {}, - h5: {} + h5: {}, } diff --git a/playgrounds/react/config/index.js b/playgrounds/react/config/index.js index bc13adf..574e816 100644 --- a/playgrounds/react/config/index.js +++ b/playgrounds/react/config/index.js @@ -5,7 +5,7 @@ const config = { deviceRatio: { 640: 2.34 / 2, 750: 1, - 828: 1.81 / 2 + 828: 1.81 / 2, }, sourceRoot: 'src', outputRoot: 'dist', @@ -16,12 +16,12 @@ const config = { patterns: [ ], options: { - } + }, }, framework: 'react', compiler: 'webpack5', cache: { - enable: false // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache + enable: false, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache }, mini: { postcss: { @@ -29,22 +29,22 @@ const config = { enable: true, config: { - } + }, }, url: { enable: true, config: { - limit: 1024 // 设定转换尺寸上限 - } + limit: 1024, // 设定转换尺寸上限 + }, }, cssModules: { enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true config: { namingPattern: 'module', // 转换模式,取值为 global/module - generateScopedName: '[name]__[local]___[hash:base64:5]' - } - } - } + generateScopedName: '[name]__[local]___[hash:base64:5]', + }, + }, + }, }, h5: { publicPath: '/', @@ -53,22 +53,22 @@ const config = { autoprefixer: { enable: true, config: { - } + }, }, cssModules: { enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true config: { namingPattern: 'module', // 转换模式,取值为 global/module - generateScopedName: '[name]__[local]___[hash:base64:5]' - } - } - } - } + generateScopedName: '[name]__[local]___[hash:base64:5]', + }, + }, + }, + }, } module.exports = function (merge) { - if (process.env.NODE_ENV === 'development') { + if (process.env.NODE_ENV === 'development') return merge({}, config, require('./dev')) - } + return merge({}, config, require('./prod')) } diff --git a/playgrounds/react/config/prod.js b/playgrounds/react/config/prod.js index e148666..151498f 100644 --- a/playgrounds/react/config/prod.js +++ b/playgrounds/react/config/prod.js @@ -1,6 +1,6 @@ module.exports = { env: { - NODE_ENV: '"production"' + NODE_ENV: '"production"', }, defineConstants: { }, @@ -33,5 +33,5 @@ module.exports = { // postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') }) // })) // } - } + }, } diff --git a/playgrounds/react/package.json b/playgrounds/react/package.json index 301cf5c..7abf4f3 100644 --- a/playgrounds/react/package.json +++ b/playgrounds/react/package.json @@ -8,6 +8,8 @@ "typescript": true, "css": "less" }, + "author": "", + "license": "MIT", "scripts": { "build:weapp": "taro build --type weapp", "build:swan": "taro build --type swan", @@ -31,8 +33,6 @@ "Android >= 4.1", "ios >= 8" ], - "author": "", - "license": "MIT", "dependencies": { "@babel/runtime": "^7.7.7", "@tarojs/components": "3.6.8", diff --git a/playgrounds/react/src/app.config.ts b/playgrounds/react/src/app.config.ts index ad8b5c8..1d8864a 100644 --- a/playgrounds/react/src/app.config.ts +++ b/playgrounds/react/src/app.config.ts @@ -22,6 +22,6 @@ export default defineAppConfig({ backgroundTextStyle: 'light', navigationBarBackgroundColor: '#fff', navigationBarTitleText: 'WeChat', - navigationBarTextStyle: 'black' - } + navigationBarTextStyle: 'black', + }, }) diff --git a/playgrounds/react/src/app.tsx b/playgrounds/react/src/app.tsx index dbe4fa1..21e826b 100644 --- a/playgrounds/react/src/app.tsx +++ b/playgrounds/react/src/app.tsx @@ -6,8 +6,7 @@ import { ACCESS_TOKEN_KEY } from './pages/const' import './app.less' const whiteRouteList = ['login'] -const App = ({ children })=> { - +function App({ children }) { useEffect(() => { // 可以通过回调拦截登录,除了白名单 history.addInterceptor(({ @@ -17,23 +16,22 @@ const App = ({ children })=> { if (!whiteRouteList.includes(short) && !Taro.getStorageSync(ACCESS_TOKEN_KEY)) { Taro.showToast({ title: '请先登录', - icon: 'error' + icon: 'error', }) setTimeout(() => { history.push('login') - }, 1500); - return true - + }, 1500) + return true } return false }) }, []) - - return ( + + return ( <> {children} - ) + ) } export default App diff --git a/playgrounds/react/src/pages/index/index.config.ts b/playgrounds/react/src/pages/index/index.config.ts index 12abc5f..a7c25c7 100644 --- a/playgrounds/react/src/pages/index/index.config.ts +++ b/playgrounds/react/src/pages/index/index.config.ts @@ -1,3 +1,3 @@ export default definePageConfig({ - navigationBarTitleText: '首页' + navigationBarTitleText: '首页', }) diff --git a/playgrounds/react/src/pages/index/index.tsx b/playgrounds/react/src/pages/index/index.tsx index 9344024..29df12d 100644 --- a/playgrounds/react/src/pages/index/index.tsx +++ b/playgrounds/react/src/pages/index/index.tsx @@ -1,15 +1,15 @@ import { useState } from 'react' -import { View, Button, Text } from '@tarojs/components' +import { Button, Text, View } from '@tarojs/components' import history from 'taro-history' -const Index = () => { +function Index() { const [count, setCount] = useState(0) - return ( + return ( @@ -21,8 +21,7 @@ const Index = () => { {count} - ) - + ) } export default Index diff --git a/playgrounds/react/src/pages/login/index.config.ts b/playgrounds/react/src/pages/login/index.config.ts index 2e697f0..9d41d86 100644 --- a/playgrounds/react/src/pages/login/index.config.ts +++ b/playgrounds/react/src/pages/login/index.config.ts @@ -1,3 +1,3 @@ export default definePageConfig({ - navigationBarTitleText: '登录' + navigationBarTitleText: '登录', }) diff --git a/playgrounds/react/src/pages/login/index.tsx b/playgrounds/react/src/pages/login/index.tsx index 876d362..72484bf 100644 --- a/playgrounds/react/src/pages/login/index.tsx +++ b/playgrounds/react/src/pages/login/index.tsx @@ -1,31 +1,29 @@ -import { View, Button } from '@tarojs/components' +import { Button, View } from '@tarojs/components' import history from 'taro-history' import Taro from '@tarojs/taro' import { ACCESS_TOKEN_KEY } from '../const' - -const Index = () => { - return ( +function Index() { + return ( - ) - + ) } export default Index diff --git a/playgrounds/react/src/pages/order/detail/index.config.ts b/playgrounds/react/src/pages/order/detail/index.config.ts index e580ccd..e34d8fc 100644 --- a/playgrounds/react/src/pages/order/detail/index.config.ts +++ b/playgrounds/react/src/pages/order/detail/index.config.ts @@ -1,3 +1,3 @@ export default definePageConfig({ - navigationBarTitleText: '订单详情' + navigationBarTitleText: '订单详情', }) diff --git a/playgrounds/react/src/pages/order/detail/index.tsx b/playgrounds/react/src/pages/order/detail/index.tsx index 83c9279..68f1e5d 100644 --- a/playgrounds/react/src/pages/order/detail/index.tsx +++ b/playgrounds/react/src/pages/order/detail/index.tsx @@ -1,25 +1,19 @@ -import { useState } from 'react' -import { View, Button, Text } from '@tarojs/components' +import { Button, Text, View } from '@tarojs/components' import history, { getParams } from 'taro-history' import Taro from '@tarojs/taro' - -const OrderDetail = () => { - const [count, setCount] = useState(0) - const {order_id} = getParams<{order_id: string }>() - return ( +function OrderDetail() { + const { order_id } = getParams<{ order_id: string }>() + return ( - - order:id: {order_id} - ) - + ) } export default OrderDetail diff --git a/playgrounds/react/src/pages/order/index.config.ts b/playgrounds/react/src/pages/order/index.config.ts index 350dbb7..cfb9404 100644 --- a/playgrounds/react/src/pages/order/index.config.ts +++ b/playgrounds/react/src/pages/order/index.config.ts @@ -1,3 +1,3 @@ export default definePageConfig({ - navigationBarTitleText: '订单搜索' + navigationBarTitleText: '订单搜索', }) diff --git a/playgrounds/react/src/pages/order/index.tsx b/playgrounds/react/src/pages/order/index.tsx index 1af2081..68c70e6 100644 --- a/playgrounds/react/src/pages/order/index.tsx +++ b/playgrounds/react/src/pages/order/index.tsx @@ -1,24 +1,22 @@ -import { View, Button, Text, Input } from '@tarojs/components' +import { Button, Input, Text, View } from '@tarojs/components' import { useState } from 'react' import history, { getParams } from 'taro-history' - -const Order = () => { +function Order() { const [q, setQ] = useState('优衣库') - const {order_id} = getParams<{order_id: string }>() - return ( + const { order_id } = getParams<{ order_id: string }>() + return ( setQ(e.detail.value)} placeholder='请输入搜索内容' /> order:id: {order_id} - ) - + ) } export default Order diff --git a/playgrounds/react/src/pages/order/search/index.config.ts b/playgrounds/react/src/pages/order/search/index.config.ts index e580ccd..e34d8fc 100644 --- a/playgrounds/react/src/pages/order/search/index.config.ts +++ b/playgrounds/react/src/pages/order/search/index.config.ts @@ -1,3 +1,3 @@ export default definePageConfig({ - navigationBarTitleText: '订单详情' + navigationBarTitleText: '订单详情', }) diff --git a/playgrounds/react/src/pages/order/search/index.tsx b/playgrounds/react/src/pages/order/search/index.tsx index 18b1fb6..379d3d5 100644 --- a/playgrounds/react/src/pages/order/search/index.tsx +++ b/playgrounds/react/src/pages/order/search/index.tsx @@ -1,13 +1,12 @@ -import { useState } from 'react' -import { View, Button, Text } from '@tarojs/components' +import { useState } from 'react' +import { Button, Text, View } from '@tarojs/components' import history, { getParams } from 'taro-history' import Taro from '@tarojs/taro' - -const OrderDetail = () => { +function OrderDetail() { const [count, setCount] = useState(0) - const {q} = getParams<{q: string }>() - return ( + const { q } = getParams<{ q: string }>() + return ( 搜索内容: {q} - ) - + ) } export default OrderDetail