[baozhangchao] 3 年前
父节点
当前提交
457f90ff63

+ 3
- 0
config/dev.js 查看文件

@@ -3,6 +3,9 @@ module.exports = {
3 3
     NODE_ENV: '"development"'
4 4
   },
5 5
   defineConstants: {
6
+    HOST: '"http://sgl-v2-test.njyunzhi.com"',
7
+    OSS: '""',
8
+    // VERSION: '"2.0.33"',
6 9
   },
7 10
   mini: {},
8 11
   h5: {}

+ 10
- 0
config/index.js 查看文件

@@ -1,3 +1,5 @@
1
+const path = require('path')
2
+
1 3
 const config = {
2 4
   projectName: 'nanyang',
3 5
   date: '2022-3-8',
@@ -18,6 +20,14 @@ const config = {
18 20
     options: {
19 21
     }
20 22
   },
23
+  alias: {
24
+    '@/assets': path.resolve(__dirname, '..', 'src/assets'),
25
+    '@/components': path.resolve(__dirname, '..', 'src/components'),
26
+    '@/layouts': path.resolve(__dirname, '..', 'src/layouts'),
27
+    '@/utils': path.resolve(__dirname, '..', 'src/utils'),
28
+    '@/store': path.resolve(__dirname, '..', 'src/store'),
29
+    '@/services': path.resolve(__dirname, '..', 'src/services'),
30
+  },
21 31
   framework: 'react',
22 32
   mini: {
23 33
     postcss: {

+ 3
- 0
config/prod.js 查看文件

@@ -3,6 +3,9 @@ module.exports = {
3 3
     NODE_ENV: '"production"'
4 4
   },
5 5
   defineConstants: {
6
+    HOST: '"http://sgl-v2-test.njyunzhi.com"',
7
+    OSS: '""',
8
+    // VERSION: '"2.0.33"',
6 9
   },
7 10
   mini: {},
8 11
   h5: {

+ 10
- 0
jsconfig.json 查看文件

@@ -0,0 +1,10 @@
1
+{
2
+  "compilerOptions": {
3
+    "baseUrl": ".",
4
+    "paths": {
5
+      "@/*": [
6
+        "./src/*"
7
+      ]
8
+    }
9
+  }
10
+}

+ 16228
- 0
package-lock.json
文件差异内容过多而无法显示
查看文件


+ 3
- 2
package.json 查看文件

@@ -37,11 +37,12 @@
37 37
   "dependencies": {
38 38
     "@babel/runtime": "^7.7.7",
39 39
     "@tarojs/components": "3.3.6",
40
+    "@tarojs/react": "3.3.6",
40 41
     "@tarojs/runtime": "3.3.6",
41 42
     "@tarojs/taro": "3.3.6",
42
-    "@tarojs/react": "3.3.6",
43
+    "react": "^17.0.0",
43 44
     "react-dom": "^17.0.0",
44
-    "react": "^17.0.0"
45
+    "weui-miniprogram": "^1.2.3"
45 46
   },
46 47
   "devDependencies": {
47 48
     "@types/webpack-env": "^1.13.6",

+ 45
- 12
project.config.json 查看文件

@@ -1,13 +1,46 @@
1 1
 {
2
-  "miniprogramRoot": "./dist",
3
-  "projectname": "nanyang",
4
-  "description": "南阳农机",
5
-  "appid": "touristappid",
6
-  "setting": {
7
-    "urlCheck": true,
8
-    "es6": false,
9
-    "postcss": false,
10
-    "minified": false
11
-  },
12
-  "compileType": "miniprogram"
13
-}
2
+    "miniprogramRoot": "dist/",
3
+    "projectname": "nanyang",
4
+    "description": "南阳农机",
5
+    "appid": "wx835627a9b9b3932a",
6
+    "setting": {
7
+        "urlCheck": true,
8
+        "es6": false,
9
+        "enhance": true,
10
+        "postcss": false,
11
+        "preloadBackgroundData": false,
12
+        "minified": false,
13
+        "newFeature": false,
14
+        "coverView": true,
15
+        "nodeModules": false,
16
+        "autoAudits": false,
17
+        "showShadowRootInWxmlPanel": true,
18
+        "scopeDataCheck": false,
19
+        "uglifyFileName": false,
20
+        "checkInvalidKey": true,
21
+        "checkSiteMap": true,
22
+        "uploadWithSourceMap": true,
23
+        "compileHotReLoad": false,
24
+        "lazyloadPlaceholderEnable": false,
25
+        "useMultiFrameRuntime": true,
26
+        "useApiHook": true,
27
+        "useApiHostProcess": true,
28
+        "babelSetting": {
29
+            "ignore": [],
30
+            "disablePlugins": [],
31
+            "outputPath": ""
32
+        },
33
+        "enableEngineNative": false,
34
+        "useIsolateContext": false,
35
+        "userConfirmedBundleSwitch": false,
36
+        "packNpmManually": false,
37
+        "packNpmRelationList": [],
38
+        "minifyWXSS": true,
39
+        "disableUseStrict": false,
40
+        "showES6CompileOption": false,
41
+        "useCompilerPlugins": false,
42
+        "minifyWXML": true
43
+    },
44
+    "compileType": "miniprogram",
45
+    "condition": {}
46
+}

+ 7
- 3
src/app.config.js 查看文件

@@ -1,7 +1,10 @@
1
+import { pages, subPackages } from './routes'
2
+
1 3
 export default {
2
-  pages: [
3
-    'pages/index/index'
4
-  ],
4
+  pages,
5
+  useExtendedLib: {
6
+    weui: true,
7
+  },
5 8
   window: {
6 9
     backgroundTextStyle: 'light',
7 10
     navigationBarBackgroundColor: '#fff',
@@ -9,3 +12,4 @@ export default {
9 12
     navigationBarTextStyle: 'black'
10 13
   }
11 14
 }
15
+

+ 13
- 6
src/app.js 查看文件

@@ -1,20 +1,27 @@
1 1
 import { Component } from 'react'
2
+import Taro from '@tarojs/taro'
3
+import { login } from '@/services/login'
2 4
 import './app.less'
3 5
 
4 6
 class App extends Component {
5 7
 
6
-  componentDidMount () {}
8
+  componentDidMount () { }
7 9
 
8
-  componentDidShow () {}
10
+  componentDidShow () { }
11
+  onLaunch (options) {
12
+    // 登录获取人员信息
13
+    Taro.login({
14
+      success: (res) => {
15
+        const { code } = res;
16
+        // login({ code })
17
+      }
18
+    })
9 19
 
10
-  componentDidHide () {}
11
-
12
-  componentDidCatchError () {}
20
+  }
13 21
 
14 22
   // this.props.children 是将要会渲染的页面
15 23
   render () {
16 24
     return this.props.children
17 25
   }
18 26
 }
19
-
20 27
 export default App

+ 54
- 0
src/app.less 查看文件

@@ -0,0 +1,54 @@
1
+.page-index {
2
+  display: flex;
3
+  flex-direction: column;
4
+  width: 100vw;
5
+  height: 100vh;
6
+  overflow: hidden;
7
+  box-sizing: border-box;
8
+  // background-color: #f2f2f2;
9
+
10
+  .index-navbar {
11
+    flex: none;
12
+  }
13
+
14
+  .index-tabbar {
15
+    flex: none;
16
+  }
17
+
18
+  .index-container {
19
+    flex: 1;
20
+    overflow: hidden;
21
+    position: relative;
22
+  }
23
+}
24
+
25
+.custom-tabbar {
26
+  background: #ffffff;
27
+  box-shadow: 0px -4px 6px 0px rgba(0, 0, 0, 0.08);
28
+  .weui-tabbar__label {
29
+    color: #c0c8d3;
30
+    font-size: 40px;
31
+    font-weight: 800;
32
+  }
33
+
34
+  .weui-bar__item_on {
35
+    .weui-tabbar__label {
36
+      color: #202020;
37
+      font-size: 50px;
38
+      font-weight: 800;
39
+    }
40
+  }
41
+}
42
+
43
+.purebtn {
44
+  margin: 0;
45
+  padding: 0;
46
+  background: transparent;
47
+  border: none;
48
+  outline: none;
49
+  line-height: 88px;
50
+
51
+  &::after {
52
+    border: none;
53
+  }
54
+}

+ 21
- 0
src/components/ButtontWX/index.jsx 查看文件

@@ -0,0 +1,21 @@
1
+
2
+import { View, Text } from '@tarojs/components'
3
+import './style.less'
4
+
5
+export default (props) => {
6
+  const { butText, butWidth, butHeight, butFontSize, butBorderRadius } = props
7
+  let butStyle = {
8
+    width: `${butWidth || 100}px`,
9
+    height: `${butHeight || 40}px`,
10
+    borderRadius: `${butBorderRadius || 0}px`,
11
+    fontSize: `${butFontSize || 20}px`
12
+  }
13
+  let butStyle2 = {
14
+    lineHeight: `${butHeight || 40}px`,
15
+  }
16
+  return (
17
+    <View className='buttont-box' style={butStyle}>
18
+      <View style={butStyle2}>{butText || '确定'}</View>
19
+    </View>
20
+  )
21
+}

+ 9
- 0
src/components/ButtontWX/style.less 查看文件

@@ -0,0 +1,9 @@
1
+.buttont-box {
2
+  background: #ff703b;
3
+  display: flex;
4
+  > View {
5
+    margin: 0 auto;
6
+    font-weight: 600;
7
+    color: #ffffff;
8
+  }
9
+}

+ 15
- 0
src/layouts/index.jsx 查看文件

@@ -0,0 +1,15 @@
1
+
2
+
3
+import useRouter from '@/utils/hooks/useRouter'
4
+import { getPageBy, getIndexPageOf } from '../routes'
5
+
6
+export default (Child) => (props) => {
7
+
8
+  // const { person } = useModel('person')
9
+  const router = useRouter()
10
+
11
+
12
+
13
+  return <Child {...props} router={router} />
14
+
15
+}

+ 11
- 0
src/pages/UserLogin/index.config.js 查看文件

@@ -0,0 +1,11 @@
1
+
2
+export default {
3
+  navigationBarTitleText: '登陆',
4
+  // navigationStyle: 'custom',
5
+  disableScroll: true,
6
+
7
+  usingComponents: {
8
+  }
9
+
10
+
11
+}

+ 9
- 0
src/pages/UserLogin/index.jsx 查看文件

@@ -0,0 +1,9 @@
1
+
2
+import { View, Text } from '@tarojs/components'
3
+
4
+export default (props) => {
5
+
6
+  return (
7
+    <View>1111111111</View>
8
+  )
9
+}

src/pages/test/index.jsx → src/pages/UserLogin/index.less 查看文件


+ 10
- 1
src/pages/index/index.config.js 查看文件

@@ -1,3 +1,12 @@
1
+
1 2
 export default {
2
-  navigationBarTitleText: '首页'
3
+  navigationBarTitleText: '首页',
4
+  // navigationStyle: 'custom',
5
+  styleIsolation: 'shared',
6
+  enableShareAppMessage: true,
7
+  disableScroll: true,
8
+  usingComponents: {
9
+    "mp-tabbar": "weui-miniprogram/tabbar/tabbar",
10
+  }
11
+
3 12
 }

+ 54
- 6
src/pages/index/index.jsx 查看文件

@@ -1,13 +1,61 @@
1
-import { View, Text } from '@tarojs/components'
1
+import React, { useState, useEffect } from 'react'
2
+import Taro, { useDidShow } from '@tarojs/taro'
3
+import withLayout from '@/layouts'
4
+
5
+import ButtontWX from '../../components/ButtontWX'
6
+import tabList from './tabbar'
7
+import Homes from './tabs/Homes'
8
+import Orders from './tabs/Orders'
9
+import Mine from './tabs/Mine'
10
+
2 11
 import './index.less'
3 12
 
4 13
 
14
+export default withLayout((props) => {
15
+  const { router } = props
16
+
17
+  const { params, path } = router
18
+  const { tab } = params || {}
19
+
20
+  const [currentTab, setCurrentTab] = useState(0)
21
+
22
+  const [isDidShow, setIsDidShow] = useState(0)
23
+
24
+
25
+  useDidShow(() => {
26
+    setIsDidShow(isDidShow + 1)
27
+  })
28
+
29
+  useEffect(() => {
30
+    if (tab) {
31
+      setCurrentTab(tab - 0)
32
+    }
33
+  }, [tab])
34
+
35
+
36
+  const handleTabChange = (e) => {
37
+    const { index } = e.detail
38
+    setCurrentTab(index)
39
+  }
5 40
 
6
-export default (props) => {
7 41
 
8 42
   return (
9
-    <View className='index'>
10
-      <Text>测试</Text>
11
-    </View>
43
+    <view className='page-index'>
44
+      {/* <ButtontWX butText='确认登陆' butWidth={100} butHeight={30} butFontSize={10} butBorderRadius={20} /> */}
45
+      <view className='index-navbar'>
46
+      </view>
47
+      <view className='index-container'>
48
+        {currentTab === 0 && <Homes />}
49
+        {currentTab === 1 && <Orders router={router} />}
50
+        {/* {currentTab === 2 && <Strategy />} */}
51
+        {currentTab === 2 && <Mine isDidShow={isDidShow} router={router} />}
52
+      </view>
53
+      <view className='index-tabbar'>
54
+        <mp-tabbar extClass='custom-tabbar' current={currentTab} list={tabList} onChange={handleTabChange}></mp-tabbar>
55
+      </view>
56
+    </view>
12 57
   )
13
-}
58
+})
59
+
60
+
61
+

+ 20
- 0
src/pages/index/tabbar.js 查看文件

@@ -0,0 +1,20 @@
1
+
2
+const tabbar = [
3
+  {//recommend_active
4
+    text: '首页',
5
+    // iconPath: require('@/assets/icons/tabbar/recommend.gif'),
6
+    // selectedIconPath: require('@/assets/icons/tabbar/recommend_active.png'),
7
+  },
8
+  {
9
+    text: '订单',
10
+    // iconPath: require('@/assets/icons/tabbar/guide.png'),
11
+    // selectedIconPath: require('@/assets/icons/tabbar/guide_active.png'),
12
+  },
13
+  {
14
+    text: '我的',
15
+    // iconPath: require('@/assets/icons/tabbar/mine.png'),
16
+    // selectedIconPath: require('@/assets/icons/tabbar/mine_active.png'),
17
+  },
18
+]
19
+
20
+export default tabbar

+ 10
- 0
src/pages/index/tabs/Homes.jsx 查看文件

@@ -0,0 +1,10 @@
1
+
2
+import { View } from "@tarojs/components"
3
+
4
+
5
+export default (props) => {
6
+
7
+  return (
8
+    <View>Home</View>
9
+  )
10
+}

+ 46
- 0
src/pages/index/tabs/Mine.jsx 查看文件

@@ -0,0 +1,46 @@
1
+
2
+import { View, Image } from "@tarojs/components"
3
+import { useDidShow } from "@tarojs/taro"
4
+import { useState } from "react"
5
+import './MineCss/style.less'
6
+
7
+
8
+export default (props) => {
9
+  const [isLoginBox, setIsLoginBox] = useState(false)
10
+
11
+  return (
12
+    <scroll-view scrollY style='height: 100%;' >
13
+
14
+      <View>
15
+        {/* 头像 */}
16
+        {
17
+          !isLoginBox ?
18
+            <View className='User-Avatar-background-falseBox'>
19
+              <Image className='User-Avatar-background-falseBox-userImg userImg' src='https://profile.csdnimg.cn/3/1/5/0_qq_42551866' />
20
+              <View className='User-Avatar-background-falseBox-userLogin' onClick={() => setIsLoginBox(true)}>点击登陆</View>
21
+            </View>
22
+            :
23
+            <View className='User-Avatar-background-trueBox'>
24
+              <View className='setPassword'>修改密码</View>
25
+              <Image className='User-Avatar-background-trueBox-userImg' src='https://profile.csdnimg.cn/3/1/5/0_qq_42551866' />
26
+              <View className='User-Avatar-background-trueBox-name textStyle' >鲍zhangchao</View>
27
+              <View className='User-Avatar-background-trueBox-phone textStyle'>18082043755</View>
28
+            </View>
29
+        }
30
+
31
+        {/* 菜单 */}
32
+        <View className='User-Setup-background'>
33
+          <View className='User-Setup-background-SetupText'>设置</View>
34
+          <View className='User-Setup-background-wxInfo'>
35
+            <View className='User-Setup-background-wxInfo-InfoCell'>
36
+              <Image className='User-Setup-background-wxInfo-InfoCell-imgae' src='https://profile.csdnimg.cn/3/1/5/0_qq_42551866' />
37
+              <View className='User-Setup-background-wxInfo-InfoCell-text'>关于我闷</View>
38
+              <View> 》 </View>
39
+            </View>
40
+
41
+          </View>
42
+        </View>
43
+      </View>
44
+    </scroll-view>
45
+  )
46
+}

+ 10
- 0
src/pages/index/tabs/Orders.jsx 查看文件

@@ -0,0 +1,10 @@
1
+
2
+import { View } from "@tarojs/components"
3
+
4
+
5
+export default (props) => {
6
+
7
+  return (
8
+    <View>Orders</View>
9
+  )
10
+}

+ 0
- 5
src/pages/test/index.config.js 查看文件

@@ -1,5 +0,0 @@
1
-export default {
2
-  navigationBarTitleText: '我的'
3
-}
4
-
5
-

+ 0
- 1
src/pages/test/index.less 查看文件

@@ -1 +0,0 @@
1
-

+ 59
- 0
src/routes.js 查看文件

@@ -0,0 +1,59 @@
1
+
2
+
3
+const Pages = [
4
+  {
5
+    title: '首页',
6
+    page: 'pages/index/index',
7
+    isIndex: true,
8
+  },
9
+
10
+];
11
+
12
+
13
+// 所有的页面
14
+const routes = Pages.map(x => ({ ...x, }))
15
+
16
+// 主包
17
+const pages = Pages.map(x => x.page);
18
+
19
+// 分包
20
+const subPages = routes.reduce((acc, route) => {
21
+  if (!route.root) return acc;
22
+
23
+  const pgs = acc[route.root] || []
24
+
25
+  return {
26
+    ...acc,
27
+    [route.root]: pgs.concat(route.page)
28
+  }
29
+}, {})
30
+
31
+const subPackages = Object.keys(subPages).map((key) => {
32
+  return {
33
+    root: key,
34
+    pages: subPages[key]
35
+  }
36
+})
37
+
38
+// 获取路径对应页面
39
+function getPageBy (path) {
40
+  return routes.filter(x => path.indexOf(x.page) > -1)[0]
41
+}
42
+
43
+// 获取角色首页
44
+function getIndexPageOf (role) {
45
+  if (role === 'person') {
46
+    return routes.filter(x => !x.root && x.isIndex)[0]
47
+  }
48
+
49
+  return routes.filter(x => x.root === role && x.isIndex)[0]
50
+}
51
+
52
+// eslint-disable-next-line import/no-commonjs
53
+module.exports = {
54
+  routes,
55
+  pages,
56
+  subPackages,
57
+  getPageBy,
58
+  getIndexPageOf
59
+}

+ 8
- 0
src/services/login.js 查看文件

@@ -0,0 +1,8 @@
1
+import request from '@/utils/request'
2
+/**
3
+ * 登录
4
+ * @param {*} id 
5
+ * @returns 
6
+ * loginParam?login哪个接口。。
7
+ */
8
+export const login = (data) => request(`/loginParam  `, { method: 'post', data })

+ 18
- 0
src/utils/codeSegment.js 查看文件

@@ -0,0 +1,18 @@
1
+/**
2
+ * object 转 queryStr
3
+ * @param {*} params 
4
+ * @returns 
5
+ */
6
+export function getQueryString (params) {
7
+  if (!params) return;
8
+
9
+  const keys = Object.keys(params)
10
+  const arr = keys.map((key) => {
11
+    const val = params[key]
12
+    if (val === null || val === undefined) return false;
13
+
14
+    return `${key}=${encodeURIComponent(val)}`
15
+  })
16
+
17
+  return arr.filter(Boolean).join('&')
18
+}

+ 27
- 0
src/utils/hooks/useRouter.js 查看文件

@@ -0,0 +1,27 @@
1
+import Taro, { useRouter } from '@tarojs/taro'
2
+// import { parseQueryString, random } from '@/utils'
3
+// import { useModel } from '@/store'
4
+import { useEffect, useRef, useState } from 'react'
5
+
6
+export default () => {
7
+  const router = useRouter()
8
+  const routerRef = useRef()
9
+
10
+
11
+  routerRef.current = router
12
+  const scene = router?.params?.scene
13
+  // const loginScene = Taro.getStorageSync('scene')
14
+
15
+  useEffect(() => {
16
+    // 没有 token 说明没有登录
17
+    const token = Taro.getStorageSync('token')
18
+    if (!token) {
19
+      return;
20
+    }
21
+
22
+
23
+
24
+  }, [scene])
25
+
26
+  return routerRef.current
27
+}

+ 64
- 0
src/utils/request.js 查看文件

@@ -0,0 +1,64 @@
1
+import Taro from '@tarojs/taro'
2
+import { getQueryString } from './codeSegment'
3
+
4
+
5
+
6
+export default (url, options) => {
7
+  const { params, skipError, header, ...leftOptions } = options || {}
8
+  const queryStr = getQueryString(params)
9
+
10
+  const urlWithParams = queryStr ? `${url}?${queryStr}` : url;
11
+  const nwUrl = `${HOST}/api/wx${urlWithParams}`
12
+
13
+  const authToken = Taro.getStorageSync('token')
14
+  const tokenHeader = authToken ? { 'X-Authorization-JWT': authToken } : {}
15
+  const nwHeader = {
16
+    ...(header || {}),
17
+    ...tokenHeader,
18
+  }
19
+
20
+  return new Promise((resolve, reject) => {
21
+    Taro.request({
22
+      ...leftOptions,
23
+      url: nwUrl,
24
+      header: nwHeader,
25
+      success: (res) => {
26
+        const { code, message, data, token } = res.data
27
+
28
+        if (token || data?.token) {
29
+          Taro.setStorage({ key: 'token', data: token || data?.token })
30
+        }
31
+
32
+        if (code === 1000) {
33
+          resolve(data)
34
+
35
+        } else {
36
+          if (!skipError) {
37
+            Taro.showToast({
38
+              title: message || '网络异常',
39
+              icon: 'none',
40
+            })
41
+          }
42
+          reject(message?.indexOf('java') > -1 ? '系统内部错误' : message)
43
+        }
44
+      },
45
+
46
+      fail: (err) => {
47
+        console.error(err)
48
+
49
+
50
+
51
+        const message = err.message || err.errMsg || err
52
+
53
+        if (!skipError) {
54
+          Taro.showToast({
55
+            title: message,
56
+            icon: 'none',
57
+          })
58
+        }
59
+
60
+        reject(message)
61
+      }
62
+    })
63
+  })
64
+}

+ 5
- 0
yarn.lock 查看文件

@@ -10414,6 +10414,11 @@ websocket-extensions@>=0.1.1:
10414 10414
   resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42"
10415 10415
   integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==
10416 10416
 
10417
+weui-miniprogram@^1.2.3:
10418
+  version "1.2.3"
10419
+  resolved "https://registry.yarnpkg.com/weui-miniprogram/-/weui-miniprogram-1.2.3.tgz#c966cdd56ec3e73c11ed8caff884fad10076feea"
10420
+  integrity sha512-PFlPKnIVTkt3CMrasTVKFEoDO4kfy1i3p4g8iU255ydZnxieGpHGa1d5gvVH9qpmxMPoIpjN57YoP/drLbJQrg==
10421
+
10417 10422
 weui@^1.1.2:
10418 10423
   version "1.1.3"
10419 10424
   resolved "https://registry.yarnpkg.com/weui/-/weui-1.1.3.tgz#0f0899bb61bb2ec603b2648367a8139298f81514"