瀏覽代碼

fix js error

ming 3 年之前
父節點
當前提交
25374f4405
共有 3 個文件被更改,包括 57 次插入27 次删除
  1. 1 1
      api/main.py
  2. 40 26
      api/static/script_util.js
  3. 16 0
      api/templates/script_index.js

+ 1 - 1
api/main.py

@@ -324,7 +324,7 @@ async def make_anchor_video(req:models.request,token: str = Depends(oauth2_schem
     save_history(req,name_hash,user_id)
     x = threading.Thread(target=gen_video_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.multiLang,user_id))
     x.start()
-    return "ok" 
+    return {'msg':'ok'}
 
 @app.post("/make_anchor_video_eng")
 async def make_anchor_video_eng(req:models.request_eng):

+ 40 - 26
api/static/script_util.js

@@ -113,12 +113,25 @@ $(".next").click(function () {
   xhr.setRequestHeader("Content-Type", "application/json");
   xhr.onreadystatechange = function () {
     if (xhr.readyState === 4) {
-      Swal.fire({
-        title: "資料已送出",
-        icon: 'success',
-        text: '資料已傳送,請耐心等候',
-        confirmButtonColor: '#3085d6',
-      });
+      responseOBJ = JSON.parse(xhr.responseText)
+      if (responseOBJ.msg=='ok')
+      {
+        Swal.fire({
+          title: "資料已送出",
+          icon: 'success',
+          text: '資料已傳送,請耐心等候',
+          confirmButtonColor: '#3085d6',
+        });
+      }
+      else{
+        Swal.fire({
+          title: "發生錯誤",
+          icon: 'error',
+          text: responseOBJ.msg,
+          confirmButtonColor: '#3085d6',
+        });
+      }
+      
     }
   };
   var data = renderXHR_data(dataOBJ)
@@ -160,30 +173,31 @@ $("#sendBTN").click(function () {
   xhr.setRequestHeader("Authorization","Bearer "+jwt_token)
   xhr.setRequestHeader("Content-Type", "application/json");
   xhr.onreadystatechange = function () {
-    
+    if (xhr.readyState === 4) {
+      responseOBJ = JSON.parse(xhr.responseText)
+      if (responseOBJ.msg=='ok')
+      {
+        Swal.fire({
+          title: "資料已送出",
+          icon: 'success',
+          text: '資料已傳送,請耐心等候',
+          confirmButtonColor: '#3085d6',
+        });
+      }
+      else{
+        Swal.fire({
+          title: "發生錯誤",
+          icon: 'error',
+          text: responseOBJ.msg,
+          confirmButtonColor: '#3085d6',
+        });
+      }
+      
+    }
   };
   var data = renderXHR_data(dataOBJ)
   console.log(data)
   result = xhr.send(objstr);
-  console.log(result)
-  if  (result !='ok') {
-    Swal.fire({
-      title: "資料已送出",
-      icon: 'success',
-      text: '資料已傳送,請耐心等候',
-      confirmButtonColor: '#3085d6',
-    });
-  }
-  else{
-    
-    Swal.fire({
-      title: '發生錯誤',
-      icon: 'error',
-      text: result.msg,
-      confirmButtonColor: '#3085d6',
-    });
-    
-  }
 });
 
 const slide_button = document.querySelector('#send_slide');

+ 16 - 0
api/templates/script_index.js

@@ -11,6 +11,22 @@ $("#btn_login").click(function () {
       // document.cookie = 'jwt_token='+responseOBJ.jwt_token    // access_token -> jwt_token
       document.cookie = 'jwt_token='+responseOBJ.access_token;
       alert('登入成功')
+      if (responseOBJ.access_token!=null)
+      {
+        Swal.fire({
+          title: "登入成功",
+          icon: 'success',
+          confirmButtonColor: '#3085d6',
+        });
+      }
+      else{
+        Swal.fire({
+          title: "登入失敗",
+          icon: 'error',
+          text: responseOBJ.detail,
+          confirmButtonColor: '#3085d6',
+        });
+      }
       window.location.replace("/index")
     }
   };