浏览代码

[feature][edit][all]

zhangwei 3 年之前
父节点
当前提交
e50b708994
共有 7 个文件被更改,包括 303 次插入167 次删除
  1. 2 1
      .gitignore
  2. 1 0
      package.json
  3. 177 119
      server/main.py
  4. 1 2
      src/App.vue
  5. 114 43
      src/components/HelloWorld.vue
  6. 6 1
      src/main.js
  7. 2 1
      vite.config.js

+ 2 - 1
.gitignore

@@ -5,4 +5,5 @@ dist-ssr
 *.local
 .vscode
 
-longVideoFactory
+longVideoFactory
+static

+ 1 - 0
package.json

@@ -7,6 +7,7 @@
     "serve": "vite preview"
   },
   "dependencies": {
+    "axios": "^0.23.0",
     "element-plus": "^1.1.0-beta.20",
     "vue": "^3.2.16"
   },

+ 177 - 119
server/main.py

@@ -2,134 +2,192 @@ import os
 import requests
 import json
 
+from flask import Flask,request,redirect
+from flask_cors import CORS 
+app = Flask(__name__,static_folder="static")
+CORS(app, resources=r'/*')
+
+
 # current_path
 current_path = os.getcwd()
 
 # 1.小程序打包
-def build_mini_program():
-    command_str = (
-    "git clone https://git.yishihui.com/weapp/longVideoFactory.git;"
-    "cd longVideoFactory;"
-    "git pull;"
-    "git checkout dev;"
-    "git pull;"
-    "n 8;"
-    "cnpm install && npm install ;"
-    "npm run build && npm run build:other;"
-    )
+# def build_mini_program():
+#     command_str = (
+#     "git clone https://git.yishihui.com/weapp/longVideoFactory.git;"
+#     "cd longVideoFactory;"
+#     "git pull;"
+#     "git checkout dev;"
+#     "git pull;"
+#     "n 8;"
+#     "cnpm install && npm install ;"
+#     "npm run build && npm run build:other;"
+#     )
     
-    if os.system(command_str) == 0:
-        print("1.打包成功")
-        # create_preview()
-    else:
-        print("1.打包失败")
+#     if os.system(command_str) == 0:
+#         print("1.打包成功")
+#         # create_preview()
+#     else:
+#         print("1.打包失败")
     
-# 2.微信编译图片
-def create_preview():
-    # 小程序 cli path for mac
-    wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
+# # 2.微信编译图片
+# def create_preview():
+#     # 小程序 cli path for mac
+#     wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
     
-    dist_path =  os.path.join(current_path,'longVideoFactory/dist/vlog')
-    code_img_path =  os.path.join(current_path,'1.png')
-    f_read = os.popen(wx_cli+" preview  --project "+dist_path+" --qr-output "+code_img_path+" --qr-format image").read()
-    if "[error]" in f_read:
-        print(f_read)
-    else:
-        print("2.微信小程序编译成功")
-
-# create_preview()
-
-# https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc
-
-def upload_img_by_feishu(token):
-    key = ""
-    url = "https://open.feishu.cn/open-apis/im/v1/images"
-    files = {
-        "image_type":(None,"message"),
-        "image":('1.png',open(os.path.join(current_path,"1.png"),"rb"),"image/png")
-    }
-    headers = {
-        "Authorization":"Bearer "+token,
-    }
-    res = requests.post(url,headers=headers,files=files,verify = False).json()
-    if res["code"] == 0:
-        key = res["data"]["image_key"]
-    else:
-        print("飞书上传图片失败")
+#     dist_path =  os.path.join(current_path,'longVideoFactory/dist/vlog')
+#     code_img_path =  os.path.join(current_path,'1.png')
+#     f_read = os.popen(wx_cli+" preview  --project "+dist_path+" --qr-output "+code_img_path+" --qr-format image").read()
+#     if "[error]" in f_read:
+#         print(f_read)
+#     else:
+#         print("2.微信小程序编译成功")
+
+# # create_preview()
+
+# # https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc
+
+# def upload_img_by_feishu(token):
+#     key = ""
+#     url = "https://open.feishu.cn/open-apis/im/v1/images"
+#     files = {
+#         "image_type":(None,"message"),
+#         "image":('1.png',open(os.path.join(current_path,"1.png"),"rb"),"image/png")
+#     }
+#     headers = {
+#         "Authorization":"Bearer "+token,
+#     }
+#     res = requests.post(url,headers=headers,files=files,verify = False).json()
+#     if res["code"] == 0:
+#         key = res["data"]["image_key"]
+#     else:
+#         print("飞书上传图片失败")
         
-    return key
-
-def tenant_access_token_by_feishu():
-    token = ""
-    url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
-    params = {
-        "app_id":"cli_a1ec07458838d00c",
-        "app_secret":"Ngm0kfaLkZnpM2T2DH7L8cM5hdAqY0hI"
-    }
-    res = requests.post(url,data=params,verify = False).json()
-    if res["code"] == 0:
-        token = res["tenant_access_token"]
-    else:
-        print("获取飞书签名失败")
-
-    return token
-
-def send_msg_by_feishu(token,img_key):
-    # webhook
-    webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc"
-    headers = {
-        "Authorization":"Bearer "+token,
-        "Content-Type": "application/json;charset=UTF-8"
-    }
-    params = {
-        "msg_type": "post",
-        "content": {
-            "post": {
-            "zh_cn": {
-                "title": "Vlog小程序预览码",
-                "content": [
-                    # [
-                    #     {
-                    #         "tag": "text",
-                    #         "text": "第二行 :"
-                    #     },
-                    #     {
-                    #         "tag": "text",
-                    #         "text": "文本测试"
-                    #     }
-                    # ],
-                    [
-                        {
-                            "tag": "img",
-                            "image_key": "img_v2_223c3413-488a-4af6-bd36-6563a9ef185g",
-                            "width": 500,
-                            "height": 500
-                        }
-                    ]]
-                }
-            }
-        }
-    }
+#     return key
+
+# def tenant_access_token_by_feishu():
+#     token = ""
+#     url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
+#     params = {
+#         "app_id":"cli_a1ec07458838d00c",
+#         "app_secret":"Ngm0kfaLkZnpM2T2DH7L8cM5hdAqY0hI"
+#     }
+#     res = requests.post(url,data=params,verify = False).json()
+#     if res["code"] == 0:
+#         token = res["tenant_access_token"]
+#     else:
+#         print("获取飞书签名失败")
+
+#     return token
+
+# def send_msg_by_feishu(token,img_key):
+#     # webhook
+#     webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc"
+#     headers = {
+#         "Authorization":"Bearer "+token,
+#         "Content-Type": "application/json;charset=UTF-8"
+#     }
+#     params = {
+#         "msg_type": "post",
+#         "content": {
+#             "post": {
+#             "zh_cn": {
+#                 "title": "Vlog小程序预览码",
+#                 "content": [
+#                     [
+#                         {
+#                             "tag": "img",
+#                             "image_key": "img_v2_223c3413-488a-4af6-bd36-6563a9ef185g",
+#                             "width": 500,
+#                             "height": 500
+#                         }
+#                     ]]
+#                 }
+#             }
+#         }
+#     }
     
-    res = requests.post(webhook_url,headers=headers,data=json.dumps(params),verify = False).json()
-    if res["StatusCode"] == 0:
-        print("飞书消息发送成功")
-    else:
-        print("飞书消息发送失败")
+#     res = requests.post(webhook_url,headers=headers,data=json.dumps(params),verify = False).json()
+#     if res["StatusCode"] == 0:
+#         print("飞书消息发送成功")
+#     else:
+#         print("飞书消息发送失败")
 
 
 
-# ------- 微信打包 ------
-# 1.小程序打包
-build_mini_program()
-# 2.微信编译图片
-create_preview()
-
-
-# -------- 飞书 --------
-# 1.获取签名 
-token = tenant_access_token_by_feishu()
-# 2.获取imgKey
-img_key = upload_img_by_feishu(token)
-# 3.飞书发送消息
-send_msg_by_feishu(token,img_key)
+# # ------- 微信打包 ------
+# # 1.小程序打包
+# # build_mini_program()
+# # 2.微信编译图片
+# # create_preview()
+
+# # 3.切换小程序环境
+
+
+# # -------- 飞书 --------
+# # 1.获取签名 
+# # token = tenant_access_token_by_feishu()
+# # 2.获取imgKey
+# # img_key = upload_img_by_feishu(token)
+# # 3.飞书发送消息
+# # send_msg_by_feishu(token,img_key)
+
+@app.route('/')
+def func():
+    
+    return 'Welcome to auto-mini-program-build-preview server. only can run on MacOS.'
+     
+# @app.route('/send',methods=['POST'])
+# def send():
+#     form_webhook_url = request.form["webrhook_url"]
+#     form_branch = request.form["branch"]
+#     form_name = request.form["name"]
+
+#     res = {"code":0,"msg":'发送成功'}
+
+#     res = {"code":1,"msg":''}
+    
+#     return request.form
+
+
+@app.route("/getBranch")
+def get_branch():
+    # 查看所有分支
+    command_str= (
+        "cd longVideoFactory;"
+        "git branch -a;"
+    )
+    f_read = os.popen(command_str).read()
+
+    branch_list = []
+    for item in f_read.split():
+        if "->" not in item and "origin/master" not in item and "HEAD" not in item and "*" not in item:
+            branch_list.append(item.replace("remotes/origin/",""))
+
+    res = {"code":0,"data":branch_list}
+    return res
+
+if __name__ == '__main__':
+    app.run(host='0.0.0.0', port=7777, debug=False)
+
+
+# 修改环境文件
+def edit_mode_by_file(project,mode):
+    path = os.path.join(current_path,"longVideoFactory/dist/"+project+"/network/volatileConfig.js")
+    file_lines = []
+    with open(path,"r") as f:
+        for item in f.readlines():
+            if "export const currentMode" in item:
+                item = "export const currentMode = MODE."+mode+" \n"
+
+            file_lines.append(item)
+        f.close()
+    
+    with open(path,"w") as f2:
+        f2.writelines(file_lines) 
+
+
+
+        f2.close()
+
+# edit_mode_by_file("vlog")

+ 1 - 2
src/App.vue

@@ -5,8 +5,7 @@ import HelloWorld from './components/HelloWorld.vue'
 </script>
 
 <template>
-  <img alt="Vue logo" src="./assets/logo.png" />
-  <HelloWorld  />
+  <HelloWorld/>
 </template>
 
 <style>

+ 114 - 43
src/components/HelloWorld.vue

@@ -1,47 +1,118 @@
-<script setup>
-import { ref, reactive } from 'vue'
+<template>
+  <el-form
+    ref="ruleForm"
+    :model="ruleForm"
+    :rules="rules"
+    label-width="120px"
+    class="demo-ruleForm"
+  >
+    <el-form-item label="webhook 地址" prop="webhook">
+      <el-input v-model="ruleForm.webhook" disabled></el-input>
+    </el-form-item>
+    <el-form-item label="项目" prop="region">
+      <el-select v-model="ruleForm.selected_project" placeholder="项目">
+        <el-option v-for="item in ruleForm.project" :label="item.label" :value="item.value"></el-option>
+      </el-select>
+    </el-form-item>
 
-const count = ref(0)
-const data = reactive({
-  platform: [{
-    value: 'vlog',
-    label: '票圈vlog',
-  }, {
-    value: 'video',
-    label: '票圈video'
-  }, {
-    value: 'shortVideo',
-    label: '票圈短视频'
-  }, {
-    value: 'longVideo',
-    label: '票圈长视频'
-  }, {
-    value: 'iMove',
-    label: '票圈爱电影'
-  }, {
-    value: 'iFunny',
-    label: '票圈最搞笑'
-  }, {
-    value: 'amazed',
-    label: '票圈最惊奇'
-  }],
-  Env: [{
-    value: 'test',
-    label: '测试'
-  }, {
-    value: 'pre',
-    label: '预发布'
-  }, {
-    value: 'prod',
-    label: '线上'
-  }]
-})
-</script>
+    <el-form-item label="分支" prop="branch">
+      <el-select v-model="ruleForm.selected_branch" placeholder="分支" filterable>
+        <el-option v-for="item in ruleForm.branch" :label="item" :value="item"></el-option>
+      </el-select>
+    </el-form-item>
+    <el-form-item label="环境" prop="region">
+      <el-select v-model="ruleForm.region" placeholder="Activity zone">
+        <el-option v-for="item in ruleForm.mode" :label="item" :value="item"></el-option>
+      </el-select>
+    </el-form-item> 
 
-<template></template>
+    <el-form-item>
+      <el-button type="primary" @click="submitForm('ruleForm')">发送飞书</el-button>
+      <el-button @click="resetForm('ruleForm')">重置</el-button>
+    </el-form-item>
+  </el-form>
+</template>
 
-<style scoped>
-a {
-  color: #42b983;
+<script>
+import axios from 'axios'
+export default {
+  data() {
+    return {
+      ruleForm: {
+        webhook: 'https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc',
+        region: '',
+        resource: '',
+        desc: '',
+        selected_project:'',
+        selected_branch:'',
+        selected_mode:'',
+        mode:['正式','测试','开发'],
+        branch:[],
+        project: [
+          {
+            label: '票圈vlog',
+            value: 'vlog'
+          }, {
+            value: 'video',
+            label: '票圈video'
+          },
+          {
+            value: 'shortVideo',
+            label: '票圈短视频'
+          }
+        ]
+      },
+      rules: {
+        webhook: [
+          {
+            required: true,
+            message: 'WebHook不能为空',
+          },
+        ],
+        region: [
+          {
+            required: true,
+            message: 'Please select Activity zone',
+            trigger: 'change',
+          },
+        ],
+        branch: [
+          {
+            required: true,
+            message: 'Please select activity resource',
+            trigger: 'change',
+          },
+        ],
+      },
+    }
+  },
+  mounted(){
+    this.getBranchList()
+  },
+  methods: {
+    // 获取分支
+    getBranchList(){
+      axios.get("http://192.168.80.185:7777/getBranch").then((res)=>{
+        res = res.data
+        if(res.code == 0){
+          this.ruleForm.branch = res.data 
+        }
+        
+      })
+    },
+    submitForm(formName) {
+      this.$refs[formName].validate((valid) => {
+        if (valid) {
+          alert('submit!')
+        } else {
+          console.log('error submit!!')
+          return false
+        }
+      })
+    },
+    resetForm(formName) {
+      this.$refs[formName].resetFields()
+    },
+  },
 }
-</style>
+</script>

+ 6 - 1
src/main.js

@@ -1,4 +1,9 @@
 import { createApp } from 'vue'
 import App from './App.vue'
+import ElementPlus from 'element-plus'
+import 'element-plus/dist/index.css'
 
-createApp(App).mount('#app')
+const app = createApp(App)
+
+app.use(ElementPlus)
+app.mount('#app')

+ 2 - 1
vite.config.js

@@ -3,5 +3,6 @@ import vue from '@vitejs/plugin-vue'
 
 // https://vitejs.dev/config/
 export default defineConfig({
-  plugins: [vue()]
+  plugins: [vue()],
+  base: './'
 })