zhangwei 3 yıl önce
ebeveyn
işleme
527fd66334
2 değiştirilmiş dosya ile 63 ekleme ve 55 silme
  1. 57 51
      server/main.py
  2. 6 4
      src/components/HelloWorld.vue

+ 57 - 51
server/main.py

@@ -2,7 +2,7 @@ import os
 import flask
 import requests
 import json
-
+import time
 from flask import Flask,request,redirect
 from flask_cors import CORS 
 app = Flask(__name__,static_folder="static")
@@ -19,13 +19,11 @@ def build_mini_program(branch):
     res = False
     command_str = (
     "cd "+current_path+ ";"
-    "git clone https://git.yishihui.com/weapp/longVideoFactory.git;"
     "cd longVideoFactory;"
     "rm -rf dist;"
-    "git pull;"
     "git checkout "+branch+";"
     "git pull;"
-    "n 8;"
+    "n 10;"
     "cnpm install && npm install ;"
     "npm run build && npm run build:other;"
     )
@@ -42,15 +40,17 @@ def build_mini_program(branch):
 # # 3.微信编译图片
 def create_preview(project,page):
     # 小程序 cli path for mac
-    wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
+    wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli "
     
     dist_path =  os.path.join(current_path,'longVideoFactory/dist/'+project)
     code_img_path =  os.path.join(current_path,'1.png')
     
     path = """ '{"pathName":"%s"}' """ % page
-    os.system(wx_cli+ "open --project " + dist_path)
-    os.system(wx_cli+ "reset-fileutils --project " + dist_path)
+    os.system(wx_cli+ " open --project " + dist_path)
+    os.system(wx_cli+ " reset-fileutils --project " + dist_path)
+    print(wx_cli+" preview  --project "+dist_path+"  --compile-condition "+path+"   --qr-output "+code_img_path+" --qr-format image")
     f_read = os.popen(wx_cli+" preview  --project "+dist_path+"  --compile-condition "+path+"   --qr-output "+code_img_path+" --qr-format image").read()
+    os.system(wx_cli+ " quit")
     if "[error]" in f_read:
         res_json["code"] = 3
         res_json["msg"] = f_read
@@ -154,58 +154,64 @@ def send_msg_by_feishu(token,img_key,url,project_name,mode_name):
 
 @app.route('/')
 def func():    
-    return 'Welcome to auto-mini-program-build-preview server. only can run on MacOS.'
+    # return 'Welcome to auto-mini-program-build-preview server. only can run on MacOS.'
+    return redirect("static/dist/index.html")
      
 @app.route('/send',methods=['POST'])
 def send():
     global send_status
-    if send_status == True:
-        res_json["code"] = 9
-        res_json["msg"] = "当前有人打包,请稍后尝试"
-        return res_json
-    send_status = True
-    res_json["code"] = 0
-    res_json["msg"] = "成功"
-    webhook_url = request.json["webhook"]
-    branch = request.json["branch"]
-    page = request.json["page"]
-    project = request.json["project"]
-    mode = request.json["mode"]
-    project_name = request.json["project_name"]
-    mode_name = request.json["mode_name"]
-    # ------- 微信打包 ------
-    # 1.小程序打包
-    build_mini_program(branch)
-    if res_json["code"] != 0:
-        send_status = False
-        return res_json
-    # 2.修改环境
-    edit_mode_by_file(project,mode)
-    if res_json["code"] != 0:
-        send_status = False
-        return res_json
-    # 3.微信编译图片
-    create_preview(project,page)
-    
+    try:
+        if send_status == True:
+            res_json["code"] = 9
+            res_json["msg"] = "当前有人打包,请稍后尝试"
+            return res_json
+        send_status = True
+        res_json["code"] = 0
+        res_json["msg"] = "成功"
+        webhook_url = request.json["webhook"]
+        branch = request.json["branch"]
+        page = request.json["page"]
+        project = request.json["project"]
+        mode = request.json["mode"]
+        project_name = request.json["project_name"]
+        mode_name = request.json["mode_name"]
+        # ------- 微信打包 ------
+        # 1.小程序打包
+        build_mini_program(branch)
+        if res_json["code"] != 0:
+            send_status = False
+            return res_json
+        # 2.修改环境
+        edit_mode_by_file(project,mode)
+        if res_json["code"] != 0:
+            send_status = False
+            return res_json
+        # 3.微信编译图片
+        time.sleep(1)
+        create_preview(project,page)
+        
+
+        # -------- 飞书 --------
+        # 1.获取签名
+        if res_json["code"] != 0:
+            send_status = False
+            return res_json
+        token = tenant_access_token_by_feishu()
+        # # 2.获取imgKey
+        if res_json["code"] != 0:
+            send_status = False
+            return res_json
+        img_key = upload_img_by_feishu(token)
+        # # 3.飞书发送消息
+        if res_json["code"] != 0:
+            send_status = False
+            return res_json
+        send_msg_by_feishu(token,img_key,webhook_url,project_name,mode_name)
 
-    # -------- 飞书 --------
-    # 1.获取签名
-    if res_json["code"] != 0:
-        send_status = False
-        return res_json
-    token = tenant_access_token_by_feishu()
-    # # 2.获取imgKey
-    if res_json["code"] != 0:
         send_status = False
-        return res_json
-    img_key = upload_img_by_feishu(token)
-    # # 3.飞书发送消息
-    if res_json["code"] != 0:
+    except:
         send_status = False
-        return res_json
-    send_msg_by_feishu(token,img_key,webhook_url,project_name,mode_name)
 
-    send_status = False
     return res_json
 
 

+ 6 - 4
src/components/HelloWorld.vue

@@ -69,6 +69,8 @@ import axios from "axios";
 export default {
   data() {
     return {
+      url:'192.168.80.253:7777',
+      // url:'http://192.168.80.185:7777',
       loading: false,
       ruleForm: {
         webhook:
@@ -97,7 +99,7 @@ export default {
             value: "TEST",
           },
         ],
-        branch: [1],
+        branch: [],
         project: [
           {
             label: "票圈vlog",
@@ -229,7 +231,7 @@ export default {
     this.getBranchpage();
   },
   methods: {
-    changeProject(item) {
+    changeProject(item,val) {
       this.ruleForm.page = item;
       this.ruleForm.selected_page = item[0].value;
       this.ruleForm.project_name = val;
@@ -239,7 +241,7 @@ export default {
     },
     // 获取分支
     getBranchpage() {
-      axios.get("http://0.0.0.0:7777/getBranch").then((res) => {
+      axios.get(this.url+"/getBranch").then((res) => {
         res = res.data;
         if (res.code == 0) {
           this.ruleForm.branch = res.data;
@@ -251,7 +253,7 @@ export default {
         if (valid) {
           this.loading = true;
           axios
-            .post("http://0.0.0.0:7777/send", {
+            .post(this.url+"/send", {
               project: this.ruleForm.selected_project,
               webhook: this.ruleForm.webhook,
               mode: this.ruleForm.selected_mode,