Bladeren bron

first commit

Your Name 4 jaren geleden
commit
4d43b6fbfd

+ 12
- 0
.editorconfig Bestand weergeven

@@ -0,0 +1,12 @@
1
+# http://editorconfig.org
2
+root = true
3
+
4
+[*]
5
+indent_style = space
6
+indent_size = 2
7
+charset = utf-8
8
+trim_trailing_whitespace = true
9
+insert_final_newline = true
10
+
11
+[*.md]
12
+trim_trailing_whitespace = false

+ 7
- 0
.eslintrc.js Bestand weergeven

@@ -0,0 +1,7 @@
1
+module.exports = {
2
+  "extends": ["taro/react"],
3
+  "rules": {
4
+    "react/jsx-uses-react": "off",
5
+    "react/react-in-jsx-scope": "off"
6
+  }
7
+}

+ 6
- 0
.gitignore Bestand weergeven

@@ -0,0 +1,6 @@
1
+dist/
2
+deploy_versions/
3
+.temp/
4
+.rn_temp/
5
+node_modules/
6
+.DS_Store

+ 10
- 0
babel.config.js Bestand weergeven

@@ -0,0 +1,10 @@
1
+// babel-preset-taro 更多选项和默认值:
2
+// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
3
+module.exports = {
4
+  presets: [
5
+    ['taro', {
6
+      framework: 'react',
7
+      ts: false
8
+    }]
9
+  ]
10
+}

+ 9
- 0
config/dev.js Bestand weergeven

@@ -0,0 +1,9 @@
1
+module.exports = {
2
+  env: {
3
+    NODE_ENV: '"development"'
4
+  },
5
+  defineConstants: {
6
+  },
7
+  mini: {},
8
+  h5: {}
9
+}

+ 70
- 0
config/index.js Bestand weergeven

@@ -0,0 +1,70 @@
1
+const config = {
2
+  projectName: 'miniapp',
3
+  date: '2021-5-12',
4
+  designWidth: 750,
5
+  deviceRatio: {
6
+    640: 2.34 / 2,
7
+    750: 1,
8
+    828: 1.81 / 2
9
+  },
10
+  sourceRoot: 'src',
11
+  outputRoot: 'dist',
12
+  plugins: [],
13
+  defineConstants: {
14
+  },
15
+  copy: {
16
+    patterns: [
17
+    ],
18
+    options: {
19
+    }
20
+  },
21
+  framework: 'react',
22
+  mini: {
23
+    postcss: {
24
+      pxtransform: {
25
+        enable: true,
26
+        config: {
27
+
28
+        }
29
+      },
30
+      url: {
31
+        enable: true,
32
+        config: {
33
+          limit: 1024 // 设定转换尺寸上限
34
+        }
35
+      },
36
+      cssModules: {
37
+        enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
38
+        config: {
39
+          namingPattern: 'module', // 转换模式,取值为 global/module
40
+          generateScopedName: '[name]__[local]___[hash:base64:5]'
41
+        }
42
+      }
43
+    }
44
+  },
45
+  h5: {
46
+    publicPath: '/',
47
+    staticDirectory: 'static',
48
+    postcss: {
49
+      autoprefixer: {
50
+        enable: true,
51
+        config: {
52
+        }
53
+      },
54
+      cssModules: {
55
+        enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
56
+        config: {
57
+          namingPattern: 'module', // 转换模式,取值为 global/module
58
+          generateScopedName: '[name]__[local]___[hash:base64:5]'
59
+        }
60
+      }
61
+    }
62
+  }
63
+}
64
+
65
+module.exports = function (merge) {
66
+  if (process.env.NODE_ENV === 'development') {
67
+    return merge({}, config, require('./dev'))
68
+  }
69
+  return merge({}, config, require('./prod'))
70
+}

+ 18
- 0
config/prod.js Bestand weergeven

@@ -0,0 +1,18 @@
1
+module.exports = {
2
+  env: {
3
+    NODE_ENV: '"production"'
4
+  },
5
+  defineConstants: {
6
+  },
7
+  mini: {},
8
+  h5: {
9
+    /**
10
+     * 如果h5端编译后体积过大,可以使用webpack-bundle-analyzer插件对打包体积进行分析。
11
+     * 参考代码如下:
12
+     * webpackChain (chain) {
13
+     *   chain.plugin('analyzer')
14
+     *     .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
15
+     * }
16
+     */
17
+  }
18
+}

+ 65
- 0
package.json Bestand weergeven

@@ -0,0 +1,65 @@
1
+{
2
+  "name": "miniapp",
3
+  "version": "1.0.0",
4
+  "private": true,
5
+  "description": "",
6
+  "templateInfo": {
7
+    "name": "redux",
8
+    "typescript": false,
9
+    "css": "sass"
10
+  },
11
+  "scripts": {
12
+    "build:weapp": "taro build --type weapp",
13
+    "build:swan": "taro build --type swan",
14
+    "build:alipay": "taro build --type alipay",
15
+    "build:tt": "taro build --type tt",
16
+    "build:h5": "taro build --type h5",
17
+    "build:rn": "taro build --type rn",
18
+    "build:qq": "taro build --type qq",
19
+    "build:jd": "taro build --type jd",
20
+    "build:quickapp": "taro build --type quickapp",
21
+    "dev:weapp": "npm run build:weapp -- --watch",
22
+    "dev:swan": "npm run build:swan -- --watch",
23
+    "dev:alipay": "npm run build:alipay -- --watch",
24
+    "dev:tt": "npm run build:tt -- --watch",
25
+    "dev:h5": "npm run build:h5 -- --watch",
26
+    "dev:rn": "npm run build:rn -- --watch",
27
+    "dev:qq": "npm run build:qq -- --watch",
28
+    "dev:jd": "npm run build:jd -- --watch",
29
+    "dev:quickapp": "npm run build:quickapp -- --watch"
30
+  },
31
+  "browserslist": [
32
+    "last 3 versions",
33
+    "Android >= 4.1",
34
+    "ios >= 8"
35
+  ],
36
+  "author": "",
37
+  "license": "MIT",
38
+  "dependencies": {
39
+    "@babel/runtime": "^7.7.7",
40
+    "@tarojs/components": "3.2.8",
41
+    "@tarojs/runtime": "3.2.8",
42
+    "@tarojs/taro": "3.2.8",
43
+    "redux-logger": "^3.0.6",
44
+    "redux-thunk": "^2.3.0",
45
+    "redux": "^4.0.0",
46
+    "react-redux": "^7.2.0",
47
+    "react-dom": "^17.0.0",
48
+    "@tarojs/react": "3.2.8",
49
+    "react": "^17.0.0"
50
+  },
51
+  "devDependencies": {
52
+    "@types/webpack-env": "^1.13.6",
53
+    "@types/react": "^17.0.2",
54
+    "@tarojs/mini-runner": "3.2.8",
55
+    "@babel/core": "^7.8.0",
56
+    "@tarojs/webpack-runner": "3.2.8",
57
+    "babel-preset-taro": "3.2.8",
58
+    "eslint-config-taro": "3.2.8",
59
+    "eslint": "^6.8.0",
60
+    "eslint-plugin-react": "^7.8.2",
61
+    "eslint-plugin-import": "^2.12.0",
62
+    "eslint-plugin-react-hooks": "^4.2.0",
63
+    "stylelint": "9.3.0"
64
+  }
65
+}

+ 13
- 0
project.config.json Bestand weergeven

@@ -0,0 +1,13 @@
1
+{
2
+  "miniprogramRoot": "./dist",
3
+  "projectname": "miniapp",
4
+  "description": "",
5
+  "appid": "touristappid",
6
+  "setting": {
7
+    "urlCheck": true,
8
+    "es6": false,
9
+    "postcss": false,
10
+    "minified": false
11
+  },
12
+  "compileType": "miniprogram"
13
+}

+ 13
- 0
project.tt.json Bestand weergeven

@@ -0,0 +1,13 @@
1
+{
2
+  "miniprogramRoot": "./",
3
+  "projectname": "miniapp",
4
+  "description": "",
5
+  "appid": "touristappid",
6
+  "setting": {
7
+    "urlCheck": true,
8
+    "es6": false,
9
+    "postcss": false,
10
+    "minified": false
11
+  },
12
+  "compileType": "miniprogram"
13
+}

+ 24
- 0
src/actions/counter.js Bestand weergeven

@@ -0,0 +1,24 @@
1
+import {
2
+  ADD,
3
+  MINUS
4
+} from '../constants/counter'
5
+
6
+export const add = () => {
7
+  return {
8
+    type: ADD
9
+  }
10
+}
11
+export const minus = () => {
12
+  return {
13
+    type: MINUS
14
+  }
15
+}
16
+
17
+// 异步的action
18
+export function asyncAdd () {
19
+  return dispatch => {
20
+    setTimeout(() => {
21
+      dispatch(add())
22
+    }, 2000)
23
+  }
24
+}

+ 11
- 0
src/app.config.js Bestand weergeven

@@ -0,0 +1,11 @@
1
+export default {
2
+  pages: [
3
+    'pages/index/index'
4
+  ],
5
+  window: {
6
+    backgroundTextStyle: 'light',
7
+    navigationBarBackgroundColor: '#fff',
8
+    navigationBarTitleText: 'WeChat',
9
+    navigationBarTextStyle: 'black'
10
+  }
11
+}

+ 30
- 0
src/app.jsx Bestand weergeven

@@ -0,0 +1,30 @@
1
+import { Component } from 'react'
2
+import { Provider } from 'react-redux'
3
+
4
+import configStore from './store'
5
+
6
+import './app.scss'
7
+
8
+const store = configStore()
9
+
10
+class App extends Component {
11
+  componentDidMount () {}
12
+
13
+  componentDidShow () {}
14
+
15
+  componentDidHide () {}
16
+
17
+  componentDidCatchError () {}
18
+
19
+  // 在 App 类中的 render() 函数没有实际作用
20
+  // 请勿修改此函数
21
+  render () {
22
+    return (
23
+      <Provider store={store}>
24
+        {this.props.children}
25
+      </Provider>
26
+    )
27
+  }
28
+}
29
+
30
+export default App

+ 0
- 0
src/app.scss Bestand weergeven


+ 2
- 0
src/constants/counter.js Bestand weergeven

@@ -0,0 +1,2 @@
1
+export const ADD = 'ADD'
2
+export const MINUS = 'MINUS'

+ 19
- 0
src/index.html Bestand weergeven

@@ -0,0 +1,19 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
5
+  <meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport">
6
+  <meta name="apple-mobile-web-app-capable" content="yes">
7
+  <meta name="apple-touch-fullscreen" content="yes">
8
+  <meta name="format-detection" content="telephone=no,address=no">
9
+  <meta name="apple-mobile-web-app-status-bar-style" content="white">
10
+  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
11
+  <title></title>
12
+  <script>
13
+    !function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;tes=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=640){r.style.fontSize="40px"}else{if(a<=320){r.style.fontSize="20px"}else{r.style.fontSize=a/320*20+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
14
+  </script>
15
+</head>
16
+<body>
17
+  <div id="app"></div>
18
+</body>
19
+</html>

+ 3
- 0
src/pages/index/index.config.js Bestand weergeven

@@ -0,0 +1,3 @@
1
+export default {
2
+  navigationBarTitleText: '首页'
3
+}

+ 48
- 0
src/pages/index/index.jsx Bestand weergeven

@@ -0,0 +1,48 @@
1
+import { Component } from 'react'
2
+import { connect } from 'react-redux'
3
+import { View, Button, Text } from '@tarojs/components'
4
+
5
+import { add, minus, asyncAdd } from '../../actions/counter'
6
+
7
+import './index.scss'
8
+
9
+
10
+@connect(({ counter }) => ({
11
+  counter
12
+}), (dispatch) => ({
13
+  add () {
14
+    dispatch(add())
15
+  },
16
+  dec () {
17
+    dispatch(minus())
18
+  },
19
+  asyncAdd () {
20
+    dispatch(asyncAdd())
21
+  }
22
+}))
23
+class Index extends Component {
24
+  componentWillReceiveProps (nextProps) {
25
+    console.log(this.props, nextProps)
26
+  }
27
+
28
+  componentWillUnmount () { }
29
+
30
+  componentDidShow () { }
31
+
32
+  componentDidHide () { }
33
+
34
+  render () {
35
+    return (
36
+      <View className='index'>
37
+        <Button className='add_btn' onClick={this.props.add}>+</Button>
38
+        <Button className='dec_btn' onClick={this.props.dec}>-</Button>
39
+        <Button className='dec_btn' onClick={this.props.asyncAdd}>async</Button>
40
+        <View><Text>{this.props.counter.num}</Text></View>
41
+        <View><Text>Hello, World</Text></View>
42
+      </View>
43
+    )
44
+  }
45
+}
46
+
47
+export default Index
48
+

+ 4
- 0
src/pages/index/index.scss Bestand weergeven

@@ -0,0 +1,4 @@
1
+.index {
2
+  flex-direction: column;
3
+  width: 100%;
4
+}

+ 22
- 0
src/reducers/counter.js Bestand weergeven

@@ -0,0 +1,22 @@
1
+import { ADD, MINUS } from '../constants/counter'
2
+
3
+const INITIAL_STATE = {
4
+  num: 0
5
+}
6
+
7
+export default function counter (state = INITIAL_STATE, action) {
8
+  switch (action.type) {
9
+    case ADD:
10
+      return {
11
+        ...state,
12
+        num: state.num + 1
13
+      }
14
+     case MINUS:
15
+       return {
16
+         ...state,
17
+         num: state.num - 1
18
+       }
19
+     default:
20
+       return state
21
+  }
22
+}

+ 6
- 0
src/reducers/index.js Bestand weergeven

@@ -0,0 +1,6 @@
1
+import { combineReducers } from 'redux'
2
+import counter from './counter'
3
+
4
+export default combineReducers({
5
+  counter
6
+})

+ 28
- 0
src/store/index.js Bestand weergeven

@@ -0,0 +1,28 @@
1
+import { createStore, applyMiddleware, compose } from 'redux'
2
+import thunkMiddleware from 'redux-thunk'
3
+import rootReducer from '../reducers'
4
+
5
+const composeEnhancers =
6
+  typeof window === 'object' &&
7
+  window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?   
8
+    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
9
+      // Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize...
10
+    }) : compose
11
+
12
+const middlewares = [
13
+  thunkMiddleware
14
+]
15
+
16
+if (process.env.NODE_ENV === 'development' && process.env.TARO_ENV !== 'quickapp') {
17
+  middlewares.push(require('redux-logger').createLogger())
18
+}
19
+
20
+const enhancer = composeEnhancers(
21
+  applyMiddleware(...middlewares),
22
+  // other store enhancers if any
23
+)
24
+
25
+export default function configStore () {
26
+  const store = createStore(rootReducer, enhancer)
27
+  return store
28
+}

+ 11866
- 0
yarn.lock
Diff onderdrukt omdat het te groot bestand
Bestand weergeven