Просмотр исходного кода

Merge branch 'master' of http://git.choozmo.com:3000/choozmo/OpenTalk

ming 3 лет назад
Родитель
Сommit
f6bb842aaa
9 измененных файлов с 350 добавлено и 69 удалено
  1. 3 0
      .vscode/settings.json
  2. 144 0
      goto.js
  3. 10 36
      index.html
  4. 37 16
      main.py
  5. BIN
      opentalk.webp
  6. 78 7
      style.css
  7. 0 1
      style.css.map
  8. 78 8
      style.scss
  9. 0 1
      test.html

+ 3 - 0
.vscode/settings.json

@@ -0,0 +1,3 @@
+{
+    "liveServer.settings.port": 5502
+}

+ 144 - 0
goto.js

@@ -0,0 +1,144 @@
+// axios
+// axios.get('http://172.105.205.52:8000/courses?tag_string=(2)')
+//   .then(function (response) {
+//     console.log(response);
+//   });
+
+//   axios.post('/user', {
+//     firstName: 'Fred',
+//     lastName: 'Flintstone'
+//   }).then(function (response) {
+//     console.log(response);
+//   })
+
+$( "#1" ).click(function() {
+    $.ajax('http://172.105.205.52:8000/tags', {
+        type: 'GET',  // http method
+        headers: { 'Access-Control-Allow-Origin': '*' },
+        success: function (res) {
+            var myJSON = JSON.stringify(res);
+            // var a = res;
+            // console.log(res);
+            var d = JSON.parse(myJSON);
+            console.log(d[0].name); 
+        },
+        
+        error: function (err) {
+            console.log(err);
+        }
+    });
+  });
+
+  $( "#2" ).click(function() {
+    $.ajax('http://172.105.205.52:8000/tags', {
+        type: 'GET',  // http method
+        headers: { 'Access-Control-Allow-Origin': '*' },
+        success: function (res) {
+            var myJSON = JSON.stringify(res);
+            // var a = res;
+            // console.log(res);
+            var d = JSON.parse(myJSON);
+            console.log(d[1].name); 
+        },
+        
+        error: function (err) {
+            console.log(err);
+        }
+    });
+  });
+  $( "#3" ).click(function() {
+    $.ajax('http://172.105.205.52:8000/tags', {
+        type: 'GET',  // http method
+        headers: { 'Access-Control-Allow-Origin': '*' },
+        success: function (res) {
+            var myJSON = JSON.stringify(res);
+            // var a = res;
+            // console.log(res);
+            var d = JSON.parse(myJSON);
+            console.log(d[2].name); 
+        },
+        
+        error: function (err) {
+            console.log(err);
+        }
+    });
+  });
+  $( "#4" ).click(function() {
+    $.ajax('http://172.105.205.52:8000/tags', {
+        type: 'GET',  // http method
+        headers: { 'Access-Control-Allow-Origin': '*' },
+        success: function (res) {
+            var myJSON = JSON.stringify(res);
+            // var a = res;
+            // console.log(res);
+            var d = JSON.parse(myJSON);
+            console.log(d[3].name); 
+        },
+        
+        error: function (err) {
+            console.log(err);
+        }
+    });
+  });
+  $( "#5" ).click(function() {
+    $.ajax('http://172.105.205.52:8000/tags', {
+        type: 'GET',  // http method
+        headers: { 'Access-Control-Allow-Origin': '*' },
+        success: function (res) {
+            var myJSON = JSON.stringify(res);
+            // var a = res;
+            // console.log(res);
+            var d = JSON.parse(myJSON);
+            console.log(d[4].name); 
+        },
+        
+        error: function (err) {
+            console.log(err);
+        }
+    });
+  });
+
+
+
+
+// jquery
+// $(document).ready(function () {
+//     $.ajax('http://172.105.205.52:8000/tags', {
+//         type: 'GET',  // http method
+//         headers: { 'Access-Control-Allow-Origin': '*' },
+//         success: function (res) {
+
+//             var myJSON = JSON.stringify(res);
+
+//             // var a = res;
+//             console.log(res);
+//             var d = JSON.parse(myJSON);
+//             console.log("start");
+//             console.log(d);
+//             console.log(d[0].name);
+//             console.log("end");
+            
+            
+               
+//         },
+        
+//         error: function (err) {
+//             console.log(err);
+//         }
+//     });
+//     $("#submit").bind('click', function () {
+//         var idiom = $("#idiom").val();
+
+//     });
+// });
+
+// $.get("date-time.php", function(data){
+//     console.log(res);
+// });
+
+$(".slider1").slick({
+    dots: true,
+    dotsClass: 'slick-dots',
+    speed: 1000,
+
+});

+ 10 - 36
index.html

@@ -1,41 +1,15 @@
 <!DOCTYPE html>
-<html lang="zh">
-
+<html lang="en">
 <head>
-    <meta charset="UTF-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>opentalk</title>
-
-    <link rel="stylesheet" href="./style.css">
+  <title>OpenTalk</title>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1">
+  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
+  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
+  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
+  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
 </head>
-
 <body>
-   <section id="banner">
-
-   </section>
-   <section class="marquee">
-    <div id="marquee-box">
-        <span class="span">Lorem ipsum dolor sit amet consectetur adipisicing elit. </span>
-        <span class="span">Lorem ipsum dolor sit amet consectetur adipisicing elit. </span>
-      </div>
-   </section>
-   <section id="tag">
-       <button class="btn" id="1">Lorem</button>
-       <button class="btn" id="2">Lorem</button>
-       <button class="btn" id="3">Lorem</button>
-       <button class="btn" id="4">Lorem</button>
-       <button class="btn" id="5">Lorem</button>
-   </section>
-   <section id="Search-result">
-       <div class="result-box">
-        <img src="https://fakeimg.pl/300x200/">
-        <div class="result-box">
-            <h1>朋友圈吸金實戰課</h1>
-            <p>酷奇文化11111</p>
-        </div>
-       </div>
-   </section>
+<img class="img-fluid" src="opentalk.webp"></img>
 </body>
-
-</html>
+</html>

+ 37 - 16
main.py

@@ -6,6 +6,12 @@ from fastapi import FastAPI, Query, UploadFile, File
 import dataset,json
 from fastapi import FastAPI
 from fastapi.middleware.cors import CORSMiddleware
+from fastapi.staticfiles import StaticFiles
+import time
+from datetime import datetime
+from PIL import Image
+import io
+
 app = FastAPI()
 origins = [
     "http://172.105.205.52",
@@ -19,7 +25,10 @@ app.add_middleware(
     allow_methods=["*"],
     allow_headers=["*"],
 )
-app.mount("/static/img", StaticFiles(directory="static/img"), name="static/img")
+
+serverADDR = '127.0.0.1:8000/'
+cover_img_dir = 'static/cover_img/'
+app.mount("/static/cover_img", StaticFiles(directory="static/cover_img"), name="static/cover_img")
 
 
 
@@ -31,8 +40,6 @@ class Tag(BaseModel):
 @app.get("/tags")
 async def get_tags():
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
-    course_table = db['course_table']
-    print(course_table.columns)
     statement = 'SELECT id,name FROM tag'
     tags = []
     for row in db.query(statement):
@@ -41,6 +48,7 @@ async def get_tags():
 
 @app.post("/tags")
 async def create_tags(tag:Tag):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
     tag_table = db['tag_table']
     pk = tag_table.insert({'name':tag.name})
     tag.id = pk
@@ -48,6 +56,7 @@ async def create_tags(tag:Tag):
 	
 @app.delete("/tags/{tag_id}")
 async def delete_tags(tag_id:int):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
     sqls = 'DELETE FROM tag_table WHERE id = '+str(tag_id)
     db.query(sqls)
     sqls = 'DELETE FROM course_tag WHERE tag_id = '+str(tag_id)
@@ -56,6 +65,7 @@ async def delete_tags(tag_id:int):
 	
 @app.put("/tags/{tag_id}")
 async def update_tags(tag_id,tag:Tag):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
     sqls = 'UPDATE tag_table\
     SET name="'+tag.name+'"\
     WHERE id='+tag_id+';'
@@ -65,6 +75,7 @@ async def update_tags(tag_id,tag:Tag):
     
 @app.get("/tags/{tag_id}")
 async def get_tags(tag_id):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
     statement = 'SELECT id,name FROM tag_table where id = '+tag_id
     for row in db.query(statement):
         result = {'id':row['id'],'name':row['name']}
@@ -76,6 +87,7 @@ async def get_tags(tag_id):
 class Course(BaseModel):
     id: int
     title: str
+    profile: str
     url: str #course website location url
     cover_img: str #img url form
     teacher_name: str
@@ -84,7 +96,7 @@ class Course(BaseModel):
     price_discount: int
     hours: int
     units: int
- '''   
+'''   
 @app.get("/courses")
 async def get_courses(tags:List[int]):
     
@@ -100,14 +112,21 @@ async def get_courses(tags:List[int]):
 '''
 @app.post("/courses")
 async def create_courses(tags: list,course:Course):
-    
-
-
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
+    #add to course table
+    course_table = db['course']
+    pk = course_table.insert({'title':course.title,'profile':course.profile,'url':course.url,'cover_img':course.cover_img,'teacher_name':course.teacher_name,
+    'price':course.price,'price_discount':course.price_discount,'hours':course.hours,'units':course.units})
+    course.id = pk
+    course_tag_table = db['course_tag']
+    for tag in tags:
+        course_tag_table.insert({'course_id':course.id,'tag_id':tag})
     return {'msg':'新增成功'}
         
 
 @app.delete("/courses/{course_id}")
 async def delete_course(course_id:int):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
     sqls = 'DELETE FROM course_table WHERE id = '+str(course_id)
     db.query(sqls)
     sqls = 'DELETE FROM course_tag WHERE course_id = '+str(course_id)
@@ -116,6 +135,7 @@ async def delete_course(course_id:int):
     
 @app.put("/courses/{course_id}")
 async def update_course(course_id,course:Course):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
     sqls = 'UPDATE course_table\
     SET title="'+course.title+'", url="'+course.url+'", hours='+str(course.hours)+',\
     teacher_name="'+course.teacher_name+'", price='+str(course.price)+', units='+str(course.units)+'\
@@ -124,16 +144,17 @@ async def update_course(course_id,course:Course):
     course.id=course_id
     return course
 
-@app.post("/uploadfile/")
+
+
+@app.post("/upload_cover_img/")
 async def create_upload_file(file: UploadFile = File(...)):
     img_name = str(time.time()).replace('.','')
-    try:
-        contents = await file.read()
-        image = Image.open(io.BytesIO(contents))
-        image= image.convert("RGB")
-        image.save(img_upload_folder+img_name+'.jpg')
-    except:
-        return {'msg':'檔案無法使用'}
-    return {"msg": 'www.choozmo.com:8168/'+tmp_img_sub_folder+img_name+'.jpg'}
+
+    contents = await file.read()
+    image = Image.open(io.BytesIO(contents))
+    image= image.convert("RGB")
+    image.save(cover_img_dir+img_name+'.jpg')
+
+    return {"msg": serverADDR+cover_img_dir+img_name+'.jpg'}
 
     


+ 78 - 7
style.css

@@ -6,16 +6,16 @@
 }
 
 body {
-  height: 3000px;
+  height: 2800px;
+}
+
+body hr {
+  margin: 20px;
 }
 
 #banner {
   width: 100vw;
   height: 500px;
-  background-image: url("https://fakeimg.pl/1650x600/");
-  background-size: cover;
-  background-repeat: no-repeat;
-  background-position: 40% 50%;
 }
 
 .marquee {
@@ -67,11 +67,82 @@ body {
 
 #tag .btn {
   padding: 15px;
-  width: 100px;
-  margin: 30px;
+  width: 150px;
+  margin: 10px;
   background-color: #CE0000;
+  border-radius: 10px;
   font-size: 24px;
   color: #fff;
   border: none;
 }
+
+#Search-result .result-box {
+  margin: 50px auto;
+  width: 700px;
+  display: -ms-grid;
+  display: grid;
+  -ms-grid-columns: (1fr)[2];
+      grid-template-columns: repeat(2, 1fr);
+  grid-gap: 10px;
+}
+
+#Search-result .result-box h1 {
+  margin: 10px;
+}
+
+#Search-result .result-box p {
+  padding: 15px 0;
+  margin: 10px;
+}
+
+#Search-result .result-box span {
+  padding: 0px 10px;
+}
+
+#logo {
+  width: 100vw;
+  text-align: center;
+}
+
+@media screen and (max-width: 1024px) {
+  #logo {
+    width: 80vw;
+    margin: 0 auto;
+  }
+}
+
+#logo .logo {
+  padding: 15px;
+  width: 150px;
+  margin: 10px;
+  background-color: #CE0000;
+  border-radius: 10px;
+  font-size: 24px;
+  color: #fff;
+  border: none;
+}
+
+#news {
+  display: -ms-grid;
+  display: grid;
+  -ms-grid-columns: (1fr)[3];
+      grid-template-columns: repeat(3, 1fr);
+  margin: 50px;
+  grid-gap: 30px;
+}
+
+#news h1 {
+  margin-bottom: 10px;
+}
+
+#news a {
+  margin-top: 20px;
+  line-height: 1.5;
+  display: inline-block;
+}
+
+#footer {
+  text-align: center;
+  line-height: 2;
+}
 /*# sourceMappingURL=style.css.map */

Разница между файлами не показана из-за своего большого размера
+ 0 - 1
style.css.map


+ 78 - 8
style.scss

@@ -3,17 +3,26 @@
     padding: 0;
     box-sizing: border-box;
 }
+
+$desktop: 1025px;
+$table: 1024px;
+$moblie: 767px;
+
+@media screen and(max-width:$table) {
+}
+@media screen and(max-width:$moblie) {
+    
+}
 body {
-    height: 3000px;
+    height: 2800px;
+    hr{
+        margin: 20px;
+    }
 }
 
 #banner {
     width: 100vw;
     height: 500px;
-    background-image: url("https://fakeimg.pl/1650x600/");
-    background-size: cover;
-    background-repeat: no-repeat;
-    background-position: 40% 50%;
 }
 .marquee {
     margin: 100px auto;
@@ -49,16 +58,77 @@ body {
     text-align: center;
     .btn{
     padding: 15px;
-    width: 100px;
-    margin: 30px;
+    width: 150px;
+    margin: 10px;
     background-color:#CE0000;
+    border-radius: 10px;;
     font-size: 24px;
     color:#fff;
     border: none;
     }
+    
+}
+
+.btn1{
+    display: none;
 }
+
+
 #Search-result{
     .result-box{
-        
+        margin: 50px auto;
+        width: 700px;
+        display: grid;
+     grid-template-columns: repeat(2,1fr );
+     grid-gap:10px;
+     h1{
+         margin: 10px;
+         
+     }
+     p{
+         padding: 15px 0;
+         margin: 10px;
+     }
+     span{
+        padding: 0px 10px;
+    
+     }
+    }
+}
+#logo{
+    width: 100vw;
+    text-align: center;
+    @media screen and(max-width:$table) {
+        width: 80vw;
+        margin: 0 auto;
+    }
+    .logo{
+    padding: 15px;
+    width: 150px;
+    margin: 10px;
+    background-color:#CE0000;
+    border-radius: 10px;;
+    font-size: 24px;
+    color:#fff;
+    border: none;
+    }
+}
+#news{
+    display: grid;
+    grid-template-columns: repeat(3,1fr );
+    margin: 50px;
+    grid-gap:30px;
+    h1{
+        margin-bottom: 10px;
     }
+    a{
+        margin-top: 20px;
+        line-height: 1.5;
+        display: inline-block;
+    }
+}
+#footer{
+text-align: center;
+line-height: 2;
 }
+

+ 0 - 1
test.html

@@ -1 +0,0 @@
-Mike test

Некоторые файлы не были показаны из-за большого количества измененных файлов