Browse Source

feat(小程序): mycli命令优化2

qq12rrr 3 weeks ago
parent
commit
6b90aa7921

+ 15 - 1
bin/index.ts

@@ -16,6 +16,7 @@ const projectConfigs = {
   hrqb: {
     appId: "458",
     miniAppId: "wxc7ed88182aa77a68",
+    CHANNELCODE: "hrqbxcx",
     LOGO: "https://comon-image.oss-cn-hangzhou.aliyuncs.com/miniPrograme/logo.png",
     HOME_LOGO:
       "https://comon-image.oss-cn-hangzhou.aliyuncs.com/miniPrograme/home_logo_hrqb.png",
@@ -23,6 +24,7 @@ const projectConfigs = {
   hrhaojie: {
     appId: "472",
     miniAppId: "wxaca93174bcaa6453",
+    CHANNELCODE: "hrhaojie",
     LOGO: "https://comon-image.oss-cn-hangzhou.aliyuncs.com/miniPrograme/logo.png",
     HOME_LOGO:
       "https://comon-image.oss-cn-hangzhou.aliyuncs.com/miniPrograme/home_logo_hrqb.png",
@@ -50,11 +52,18 @@ async function writeJsonFile(filePath, data) {
 }
 
 // 更新配置项在指定文件中
-async function updateConfigInFile(filePath, newAPPID, newLOGO, newHOME_LOGO) {
+async function updateConfigInFile(
+  filePath,
+  newAPPID,
+  newCHANNELCODE,
+  newLOGO,
+  newHOME_LOGO
+) {
   try {
     let data = await fs.readFile(filePath, "utf8");
     const updates = [
       { key: "APPID: ", value: `'"${newAPPID}"',` },
+      { key: "CHANNELCODE: ", value: `'"${newCHANNELCODE}"',` },
 
       // 因现在惠融好借和惠融钱包的图片资源都是一样的,所以LOGO和HOME_LOGO暂时这部分代码暂时注释掉
       // { key: "LOGO: ", value: `'"${newLOGO}"',` },
@@ -76,6 +85,9 @@ async function updateConfigInFile(filePath, newAPPID, newLOGO, newHOME_LOGO) {
     if (data !== updatedData) {
       await fs.writeFile(filePath, updatedData, "utf8");
       console.log(`更新成功: ${filePath} 中的 APPID 已更新为 ${newAPPID}`);
+      console.log(
+        `更新成功: ${filePath} 中的 CHANNELCODE 已更新为 ${newCHANNELCODE}`
+      );
       // console.log(`更新成功: ${filePath} 中的 LOGO 已更新为 ${newLOGO}`);
       // console.log(
       //   `更新成功: ${filePath} 中的 HOME_LOGO 已更新为 ${newHOME_LOGO}`
@@ -109,12 +121,14 @@ async function updateProjectConfig(projectName) {
     updateConfigInFile(
       devFilePath,
       projectConfig.appId,
+      projectConfig.CHANNELCODE,
       projectConfig.LOGO,
       projectConfig.HOME_LOGO
     ),
     updateConfigInFile(
       prodFilePath,
       projectConfig.appId,
+      projectConfig.CHANNELCODE,
       projectConfig.LOGO,
       projectConfig.HOME_LOGO
     ),

+ 1 - 0
config/dev.js

@@ -9,6 +9,7 @@ module.exports = {
     HOST: '"https://api.hrshuke.cn"',
     // 格式化后,这条注释下的值有换行,请手动修改格式回去!!!否则mycli修改不会生效!!!键后面的冒号后面还有个空格!!!
     APPID: '"458"',
+    CHANNELCODE: '"hrqbxcx"',
     LOGO: '"https://comon-image.oss-cn-hangzhou.aliyuncs.com/miniPrograme/logo.png"',
     HOME_LOGO: '"https://comon-image.oss-cn-hangzhou.aliyuncs.com/miniPrograme/home_logo_hrqb.png"',
     // 

+ 1 - 0
config/prod.js

@@ -9,6 +9,7 @@ module.exports = {
     // "HOST": '"http://192.168.0.168:810"',
     // 格式化后,如果HOME_LOGO和APPID的值有换行,请手动修改格式回去!!!否则mycli修改不会生效!!!HOME_LOGO:还有APPID:后面还有个空格!!!
     APPID: '"458"',
+    CHANNELCODE: '"hrqbxcx"',
     LOGO: '"https://comon-image.oss-cn-hangzhou.aliyuncs.com/miniPrograme/logo.png"',
     HOME_LOGO: '"https://comon-image.oss-cn-hangzhou.aliyuncs.com/miniPrograme/home_logo_hrqb.png"',
   },

+ 7 - 5
src/config/index.d.ts

@@ -1,10 +1,12 @@
-export type EnvType = "DEVELOPMENT" | "TEST" | "PRODUCTION" | "UAT"
+export type EnvType = "DEVELOPMENT" | "TEST" | "PRODUCTION" | "UAT";
 
 export interface Env {
-    HOST: string,
-    ENV: EnvType,
-    APPID: string,
-    HOME_LOGO:string,
+  HOST: string;
+  ENV: EnvType;
+  APPID: string;
+  CHANNELCODE: string;
+  LOGO: string;
+  HOME_LOGO: string;
 }
 
 declare const APPConfig: Env;

+ 7 - 5
src/config/index.js

@@ -1,6 +1,8 @@
 export default {
-    HOST: HOST,
-    ENV: ENV,
-    APPID: APPID,
-    HOME_LOGO: HOME_LOGO,
-}
+  HOST: HOST,
+  ENV: ENV,
+  APPID: APPID,
+  CHANNELCODE: CHANNELCODE,
+  LOGO: LOGO,
+  HOME_LOGO: HOME_LOGO,
+};

+ 1 - 1
src/helper/userHelper.ts

@@ -13,7 +13,7 @@ export default class UserHelper {
    * @param code 小程序获取的Code
    * @param [channelCode] 渠道号
    */
-  public static async userWxLogin(code: string, channelCode: string = 'hrqbxcx') {
+  public static async userWxLogin(code: string, channelCode: string = APPConfig.CHANNELCODE) {
 
     let result = await UserApi.wxLoginUsingGet({
       params: { code, channelCode },

+ 3 - 3
src/pages/home/index.tsx

@@ -51,7 +51,7 @@ const Home = () => {
 
   const channelResult: any = useRequest(() => {
     return UserApi.homeFetchChannel({
-      data: { channelCode: "hrqbxcx", refer: "" },
+      data: { channelCode: APPConfig.CHANNELCODE, refer: "" },
     })
       .toData()
       .then((res) => {
@@ -97,7 +97,7 @@ const Home = () => {
   };
 
   const carLoanFlowHandler = async () => {
-    const DEFAULT_CHANNEL_CODE = "hrqbxcx";
+    const DEFAULT_CHANNEL_CODE = APPConfig.CHANNELCODE;
 
     const url =
       "https://m1.h5.hrshuke.cn/carv2/" + (channelCode || DEFAULT_CHANNEL_CODE);
@@ -107,7 +107,7 @@ const Home = () => {
   };
 
   const houseLoanFlowHandler = async () => {
-    const DEFAULT_CHANNEL_CODE = "hrqbxcx";
+    const DEFAULT_CHANNEL_CODE = APPConfig.CHANNELCODE;
 
     const url =
       "https://m1.h5.hrshuke.cn/house/" + (channelCode || DEFAULT_CHANNEL_CODE);

+ 2 - 2
src/pages/user/components/LoginBox.tsx

@@ -191,7 +191,7 @@ const LoginBox = forwardRef((props, ref) => {
       setIsGetValidate(!isGetValidate);
       setTime(60); // 重置倒计时
       let obj = {
-        channelCode: channelCode || "hrqbxcx",
+        channelCode: channelCode || APPConfig.CHANNELCODE,
         phone: ctyptoUtil.AesEncode(phone),
         sceneType: "register",
       };
@@ -250,7 +250,7 @@ const LoginBox = forwardRef((props, ref) => {
       return;
     }
     let obj = {
-      channelCode: channelCode || "hrqbxcx",
+      channelCode: channelCode || APPConfig.CHANNELCODE,
       phone: ctyptoUtil.AesEncode(phone),
       sceneType: "register",
       uctrackid: "",