Skip to content

Commit

Permalink
style: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
baozouai committed Jul 18, 2023
1 parent 37b7cb2 commit 4bc9dfd
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 109 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -77,6 +77,6 @@
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"src/**/*.ts": "eslint --fix"
"*": "eslint --fix"
}
}
7 changes: 0 additions & 7 deletions playgrounds/react/.eslintrc.js

This file was deleted.

6 changes: 3 additions & 3 deletions playgrounds/react/babel.config.js
Expand Up @@ -4,7 +4,7 @@ module.exports = {
presets: [
['taro', {
framework: 'react',
ts: true
}]
]
ts: true,
}],
],
}
4 changes: 2 additions & 2 deletions playgrounds/react/config/dev.js
@@ -1,9 +1,9 @@
module.exports = {
env: {
NODE_ENV: '"development"'
NODE_ENV: '"development"',
},
defineConstants: {
},
mini: {},
h5: {}
h5: {},
}
36 changes: 18 additions & 18 deletions playgrounds/react/config/index.js
Expand Up @@ -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',
Expand All @@ -16,35 +16,35 @@ 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: {
pxtransform: {
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: '/',
Expand All @@ -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'))
}
15 changes: 0 additions & 15 deletions playgrounds/react/config/plugin.js

This file was deleted.

4 changes: 2 additions & 2 deletions playgrounds/react/config/prod.js
@@ -1,6 +1,6 @@
module.exports = {
env: {
NODE_ENV: '"production"'
NODE_ENV: '"production"',
},
defineConstants: {
},
Expand Down Expand Up @@ -33,5 +33,5 @@ module.exports = {
// postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') })
// }))
// }
}
},
}
4 changes: 2 additions & 2 deletions playgrounds/react/package.json
Expand Up @@ -8,6 +8,8 @@
"typescript": true,
"css": "less"
},
"author": "",
"license": "MIT",
"scripts": {
"build:weapp": "taro build --type weapp",
"build:swan": "taro build --type swan",
Expand All @@ -31,8 +33,6 @@
"Android >= 4.1",
"ios >= 8"
],
"author": "",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.7.7",
"@tarojs/components": "3.6.8",
Expand Down
4 changes: 2 additions & 2 deletions playgrounds/react/src/app.config.ts
Expand Up @@ -22,6 +22,6 @@ export default defineAppConfig({
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat',
navigationBarTextStyle: 'black'
}
navigationBarTextStyle: 'black',
},
})
16 changes: 7 additions & 9 deletions playgrounds/react/src/app.tsx
Expand Up @@ -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(({
Expand All @@ -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
2 changes: 1 addition & 1 deletion playgrounds/react/src/pages/index/index.config.ts
@@ -1,3 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '首页'
navigationBarTitleText: '首页',
})
11 changes: 5 additions & 6 deletions 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 (
<View className='index'>
<Button onClick={() => {
history.push<{ order_id: string }>('order', {
order_id: '123'
order_id: '123',
})
}}
>跳到订单</Button>
Expand All @@ -21,8 +21,7 @@ const Index = () => {
<Button onClick={() => setCount(c => c - 1)}>+</Button>
<Text>{count}</Text>
</View>
)

)
}

export default Index
2 changes: 1 addition & 1 deletion playgrounds/react/src/pages/login/index.config.ts
@@ -1,3 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '登录'
navigationBarTitleText: '登录',
})
18 changes: 8 additions & 10 deletions 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 (
<View className='index'>
<Button onClick={() => {
Taro.showLoading({
title: '正在登录',
mask: true,
})

setTimeout(() => {
Taro.hideLoading()
Taro.showToast({title: '登录成功', mask: true })
Taro.showToast({ title: '登录成功', mask: true })
Taro.setStorageSync(ACCESS_TOKEN_KEY, '123')
setTimeout(() => {
history.reLaunch('index/index')
}, 1000);
}, 2000);
}, 1000)
}, 2000)
}}
>点击登录</Button>
</View>
)

)
}

export default Index
2 changes: 1 addition & 1 deletion playgrounds/react/src/pages/order/detail/index.config.ts
@@ -1,3 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '订单详情'
navigationBarTitleText: '订单详情',
})
16 changes: 5 additions & 11 deletions 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 (
<View className='index'>
<Button onClick={() => {
console.log(Taro)
history.push('index/index')
}}
>跳到首页</Button>
<Button onClick={() => setCount(c => c + 1)}>-</Button>
<Button onClick={() => setCount(c => c - 1)}>+</Button>
<Text> order:id: {order_id}</Text>
</View>
)

)
}

export default OrderDetail
2 changes: 1 addition & 1 deletion playgrounds/react/src/pages/order/index.config.ts
@@ -1,3 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '订单搜索'
navigationBarTitleText: '订单搜索',
})
14 changes: 6 additions & 8 deletions 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 (
<View className='index'>
<Button onClick={history.pushBind('index/index')}>跳到首页</Button>
<Button onClick={() => {
history.push('order/detail', { order_id: 'xxx123'})
history.push('order/detail', { order_id: 'xxx123' })
}}
>跳到详情</Button>
<Button onClick={history.pushBind('order/search', { q: q || '优衣库' })}>跳到搜索</Button>
<Input value={q} onInput={e => setQ(e.detail.value)} placeholder='请输入搜索内容' />
<Text> order:id: {order_id}</Text>
</View>
)

)
}

export default Order
2 changes: 1 addition & 1 deletion playgrounds/react/src/pages/order/search/index.config.ts
@@ -1,3 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '订单详情'
navigationBarTitleText: '订单详情',
})

0 comments on commit 4bc9dfd

Please sign in to comment.