Explorar o código

feat: 摇一摇修改全局环境

huangzhichao hai 1 ano
pai
achega
08f352f67e
Modificáronse 7 ficheiros con 87 adicións e 66 borrados
  1. 1 1
      config/index.ts
  2. 25 24
      package.json
  3. 13 0
      src/env.ts
  4. 1 0
      src/http/index.ts
  5. 4 7
      src/pages/index/index.tsx
  6. 13 34
      src/plugin/components/custom/index.tsx
  7. 30 0
      src/plugin/index.ts

+ 1 - 1
config/index.ts

@@ -2,7 +2,7 @@ const path = require('path')
 
 const config = {
   projectName: 'mxplugin',
-  date: '2023-11-13',
+  date: '2023-11-29',
   designWidth: 750,
   deviceRatio: {
     '640': 2.34 / 2,

+ 25 - 24
package.json

@@ -9,8 +9,8 @@
     "css": "less"
   },
   "scripts": {
-    "build": "taro build --plugin weapp",
-    "dev": "npm run build -- --watch"
+    "build": "cross-env NODE_ENV=production taro build --plugin weapp",
+    "dev": "cross-env NODE_ENV=development taro build --plugin weapp --watch"
   },
   "author": "",
   "license": "MIT",
@@ -23,45 +23,46 @@
     "@babel/runtime": "^7.7.7",
     "@tarojs/components": "3.6.19",
     "@tarojs/helper": "3.6.19",
-    "@tarojs/plugin-platform-weapp": "3.6.19",
+    "@tarojs/plugin-framework-react": "3.6.19",
     "@tarojs/plugin-platform-alipay": "3.6.19",
-    "@tarojs/plugin-platform-tt": "3.6.19",
-    "@tarojs/plugin-platform-swan": "3.6.19",
+    "@tarojs/plugin-platform-h5": "3.6.19",
     "@tarojs/plugin-platform-jd": "3.6.19",
     "@tarojs/plugin-platform-qq": "3.6.19",
-    "@tarojs/plugin-platform-h5": "3.6.19",
+    "@tarojs/plugin-platform-swan": "3.6.19",
+    "@tarojs/plugin-platform-tt": "3.6.19",
+    "@tarojs/plugin-platform-weapp": "3.6.19",
+    "@tarojs/react": "3.6.19",
     "@tarojs/runtime": "3.6.19",
     "@tarojs/shared": "3.6.19",
     "@tarojs/taro": "3.6.19",
-    "@tarojs/plugin-framework-react": "3.6.19",
-    "@tarojs/react": "3.6.19",
-    "react-dom": "^18.0.0",
-    "react": "^18.0.0"
+    "react": "^18.0.0",
+    "react-dom": "^18.0.0"
   },
   "devDependencies": {
     "@babel/core": "^7.8.0",
+    "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
     "@tarojs/cli": "3.6.19",
-    "@types/webpack-env": "^1.13.6",
-    "postcss": "^8.4.18",
-    "@types/react": "^18.0.0",
-    "webpack": "^5.78.0",
     "@tarojs/taro-loader": "3.6.19",
     "@tarojs/webpack5-runner": "3.6.19",
+    "@types/node": "^18.15.11",
+    "@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-preset-taro": "3.6.19",
-    "eslint-config-taro": "3.6.19",
+    "cross-env": "^7.0.3",
     "eslint": "^8.12.0",
-    "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
-    "react-refresh": "^0.11.0",
-    "eslint-plugin-react": "^7.8.2",
+    "eslint-config-taro": "3.6.19",
     "eslint-plugin-import": "^2.12.0",
+    "eslint-plugin-react": "^7.8.2",
     "eslint-plugin-react-hooks": "^4.2.0",
+    "postcss": "^8.4.18",
+    "react-refresh": "^0.11.0",
+    "sass": "^1.69.5",
+    "sass-loader": "^13.3.2",
     "stylelint": "9.3.0",
-    "@typescript-eslint/parser": "^5.20.0",
-    "@typescript-eslint/eslint-plugin": "^5.20.0",
-    "typescript": "^4.1.0",
     "ts-node": "^10.9.1",
-    "@types/node": "^18.15.11",
-    "sass": "^1.69.5",
-    "sass-loader": "^13.3.2"
+    "typescript": "^4.1.0",
+    "webpack": "^5.78.0"
   }
 }

+ 13 - 0
src/env.ts

@@ -0,0 +1,13 @@
+import Taro from "@tarojs/taro"
+const env = process.env.NODE_ENV
+
+export function storageEnv(env) {
+  Taro.setStorage({
+    key: 'env',
+    data: env
+  })
+}
+
+export const ENV_LIST = ['development', 'staging', 'production']
+
+storageEnv(env)

+ 1 - 0
src/http/index.ts

@@ -0,0 +1 @@
+console.log(process.env.NODE_ENV)

+ 4 - 7
src/pages/index/index.tsx

@@ -6,20 +6,17 @@ import './index.less'
 
 // console.log(Demo)
 // debugger
+// console.log(Taro.getApp())
 
 const myPluginInterface = Taro.requirePlugin('myPlugin')
 
 const Index: React.FC = () => {
   useLoad(() => {
-    myPluginInterface.sayHello()
-    const answer = myPluginInterface.answer
-    console.log('answer: ', answer)
+    // myPluginInterface.sayHello()
+    // const answer = myPluginInterface.answer
+    // console.log('answer: ', answer)
   })
 
-  function hasCllick() {
-    console.log('hasCllick')
-  }
-
   return (
     <View className='index'>
       <custom props={{width: "300"}} />

+ 13 - 34
src/plugin/components/custom/index.tsx

@@ -10,18 +10,18 @@ const Custom: React.FC = (props: PropsWithChildren<CustomPropsType>) => {
 
   const customWidth = props.width
 
-  useReady(() => {
-    Taro.request({
-      url: 'https://api.piaoquantv.com/ad/self/inAbPredict',
-      method: 'POST',
-      success(res) {
-        console.log(res)
-      },
-      fail(err) {
-        console.log(err)
-      }
-    })
-  })
+  // useReady(() => {
+  //   Taro.request({
+  //     url: 'https://api.piaoquantv.com/ad/self/inAbPredict',
+  //     method: 'POST',
+  //     success(res) {
+  //       console.log(res)
+  //     },
+  //     fail(err) {
+  //       console.log(err)
+  //     }
+  //   })
+  // })
 
   function clickPayment() {
     console.log('支付')
@@ -47,30 +47,9 @@ const Custom: React.FC = (props: PropsWithChildren<CustomPropsType>) => {
 
   return (
     <View onClick={clickCustom} style={{width: customWidth + 'px'}}>
-      <Navigator url='plugin-private://wxf7261ed54f2e450e/pages/h5/index'>
-        <Button>H5</Button>
-      </Navigator>
-
-      <Navigator url='plugin-private://wxf7261ed54f2e450e/pages/miniWeb/index'>
-        <Button>半屏</Button>
-      </Navigator>
-
-      <Navigator url='plugin-private://wxf7261ed54f2e450e/pages/webview/index'>
-        <Button>全屏</Button>
-      </Navigator>
-
       <Navigator url='plugin-private://wxf7261ed54f2e450e/pages/webview/index'>
-        {/* <Video autoplay controls={false} loop src='https://xycdn.yishihui.com/ad/prod/video/material_AD_1700025739_1700025739924.mp4' /> */}
+        <Video autoplay={false} controls={false} loop src='https://xycdn.yishihui.com/ad/prod/video/material_AD_1700025739_1700025739924.mp4' />
       </Navigator>
-      <Button onClick={clickPayment}>支付</Button>
-      <FunctionalPageNavigator
-        name="loginAndGetUserInfo"
-        version="develop"
-        onSuccess={loginSuccess}
-        onFail={loginFail}
-      >
-        <Button className="login">登录到插件</Button>
-      </FunctionalPageNavigator>
     </View>
   )
 }

+ 30 - 0
src/plugin/index.ts

@@ -1,3 +1,33 @@
+import { storageEnv, ENV_LIST } from '@/env'
+
+function changeEnvByShake() {
+  let flag = true
+  wx.onAccelerometerChange(({ x, y, z }) => {
+    if (!flag)
+      return
+
+    if (x > 1 || y > 1 || z > 1) {
+      flag = false
+      wx.vibrateLong()
+
+      wx.showActionSheet({
+        itemList: ['测试环境', '预发环境', '正式环境'],
+        success (res) {
+          storageEnv(ENV_LIST[res.tapIndex])
+          setTimeout(() => {
+            flag = true
+          }, 200)
+        },
+        fail () {
+          flag = true
+        }
+      })
+    }
+  })
+}
+
+changeEnvByShake()
+
 export function sayHello () {
   console.log('Hello plugin!')
 }