huangyan il y a 10 mois
Parent
commit
f38595f46e
8 fichiers modifiés avec 71 ajouts et 44 suppressions
  1. 42 0
      controllers/admin/login.go
  2. 18 6
      controllers/product.go
  3. 1 1
      controllers/uploadImage.go
  4. 1 1
      main.go
  5. 1 0
      routers/router.go
  6. 2 0
      service/user.go
  7. 3 33
      views/about.html
  8. 3 3
      views/index.html

+ 42 - 0
controllers/admin/login.go

@@ -3,13 +3,24 @@ package admin
 import (
 	"cc-officialweb/models"
 	"cc-officialweb/service"
+	"encoding/json"
 	"github.com/beego/beego/v2/adapter/validation"
 	beego "github.com/beego/beego/v2/server/web"
+	"github.com/go-playground/validator/v10"
 )
 
 type LoginController struct {
 	beego.Controller
 }
+type JSON struct {
+	Code int
+	Msg  string
+	Data any
+}
+type JSONS struct {
+	Total int
+	Data  any
+}
 
 func (l *LoginController) Get() {
 	l.TplName = "admin/login.html"
@@ -41,3 +52,34 @@ func (l *LoginController) Post() {
 	}
 	l.TplName = "admin/login.html"
 }
+
+// Login 登录接口
+func (l *LoginController) Login() {
+	var user models.User
+	// 获取POST参数
+	err := json.Unmarshal(l.Ctx.Input.RequestBody, &user)
+	if err != nil {
+		l.Data["json"] = &JSON{Code: 103, Msg: "json格式错误"}
+		l.ServeJSON()
+		return
+	}
+	// 进行验证和登录检查
+	validate := validator.New()
+	unva := validate.Var(user.Username, "required")
+	pwdva := validate.Var(user.Password, "required")
+	if unva != nil || pwdva != nil {
+		l.Data["json"] = &JSON{Code: 103, Msg: "用户名密码不能为空"}
+		l.ServeJSON()
+		return
+	} else {
+		token := service.Login(user)
+		if token != "" {
+			l.Data["json"] = &JSON{Code: 200, Msg: "登录成功", Data: token}
+			l.ServeJSON()
+		} else {
+			l.Data["json"] = &JSON{Code: 103, Msg: "用户名密码错误"}
+			l.ServeJSON()
+			return
+		}
+	}
+}

+ 18 - 6
controllers/product.go

@@ -4,7 +4,6 @@ import (
 	"cc-officialweb/models"
 	"cc-officialweb/service"
 	"cc-officialweb/unity"
-	"cc-officialweb/utils"
 	"encoding/json"
 	beego "github.com/beego/beego/v2/server/web"
 	"github.com/go-playground/validator/v10"
@@ -100,20 +99,33 @@ func (s *ProductController) GetAllProduct() {
 func (s *ProductController) UpdateProductById() {
 	var productDto models.ProductDto
 	var product models.Products
-	//id := s.GetString("id")
-	//atoi, _ := strconv.Atoi(id)
-	err := json.Unmarshal(s.Ctx.Input.RequestBody, &product)
+	err := json.Unmarshal(s.Ctx.Input.RequestBody, &productDto)
 	if err != nil {
 		s.Data["json"] = &JSON{Code: 101, Msg: "json解析失败"}
 		s.ServeJSON()
 		return
 	}
-	utils.CopyWithReflection(&productDto, &product)
+	product.Title = productDto.Title                             //标题
+	product.Synopsis = productDto.Synopsis                       //简介
+	product.Detail = productDto.Detail                           //详情
+	product.Type = productDto.Type                               //类型 1.产品 2.服务
+	product.Ptype = productDto.Ptype                             //产品类型	软件 硬件
+	product.IsIndex = productDto.IsIndex                         //是否首页显示
+	product.Url = productDto.Url                                 //图片链接
+	product.ProductIntroduction = productDto.ProductIntroduction //产品介绍
+	product.TechnicalParameters = productDto.TechnicalParameters //技术参数
+	product.Instructions = productDto.Instructions               //使用说明
+	product.SupportingSoftware = productDto.SupportingSoftware   //配套软件
+	product.OptionalAccessories = productDto.OptionalAccessories //可选配件
+	product.IsActive = productDto.IsActive
 	_, err = unity.UpdateById(productDto.ID, product)
 	if err != nil {
-		s.Data["json"] = &JSON{Code: 200, Msg: "修改成功"}
+		s.Data["json"] = &JSON{Code: 102, Msg: err.Error()}
 		s.ServeJSON()
 		return
+	} else {
+		s.Data["json"] = &JSON{Code: 200, Msg: "修改成功"}
+		s.ServeJSON()
 	}
 }
 

+ 1 - 1
controllers/uploadImage.go

@@ -18,7 +18,7 @@ type UploadImageController struct {
 }
 type JSON struct {
 	Code int
-	Msg  string
+	Msg  any
 	Data any
 }
 type JSONS struct {

+ 1 - 1
main.go

@@ -7,6 +7,6 @@ import (
 
 func main() {
 	beego.SetStaticPath("/image", "./static/upload")
-	beego.Run()
 
+	beego.Run()
 }

+ 1 - 0
routers/router.go

@@ -26,6 +26,7 @@ func init() {
 
 	beego.Router("/admin", &admin.LoginController{})
 	beego.Router("/login", &admin.LoginController{})
+	beego.Router("/api/logon", &admin.LoginController{}, "post:Login")
 	beego.Router("/admin/index", &admin.IndexController{})
 
 	beego.Router("/api/upload", &controllers.UploadImageController{})

+ 2 - 0
service/user.go

@@ -3,9 +3,11 @@ package service
 import (
 	"cc-officialweb/models"
 	"cc-officialweb/utils"
+	"fmt"
 )
 
 func Login(user models.User) string {
+	fmt.Println("user:", user.Username, user.Password)
 	pwd := utils.MD5(user.Password)
 	tx := utils.DB.Where("username = ?", user.Username).Where("password = ?", pwd).First(&user)
 	if tx.RowsAffected > 0 {

+ 3 - 33
views/about.html

@@ -19,7 +19,7 @@
     <!-- Bootstrap CSS File -->
     <link href="../static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
 
-
+    <script src="https://unpkg.com/naive-ui"></script>
     <!-- Libraries CSS Files -->
     <link href="../static/lib/font-awesome/css/font-awesome.min.css" rel="stylesheet">
     <link href="../static/lib/animate/animate.min.css" rel="stylesheet">
@@ -28,34 +28,10 @@
     <link href="../static/lib/magnific-popup/magnific-popup.css" rel="stylesheet">
     <link href="../static/lib/ionicons/css/ionicons.min.css" rel="stylesheet">
 
-    <!-- Main Stylesheet File -->
     <link href="../static/css/style.css" rel="stylesheet">
 </head>
 
 <body id="body">
-
-<!--==========================
-  Top Bar
-============================-->
-<!--  <section id="topbar" class="d-none d-lg-block">-->
-<!--    <div class="container clearfix">-->
-<!--      <div class="contact-info float-left">-->
-<!--        <i class="fa fa-envelope-o"></i> <a href="mailto:contact@example.com">name@websitename.com</a>-->
-<!--        <i class="fa fa-phone"></i> +1 2345 67855 22-->
-<!--      </div>-->
-<!--      <div class="social-links float-right">-->
-<!--        <a href="#" class="twitter"><i class="fa fa-twitter"></i></a>-->
-<!--        <a href="#" class="facebook"><i class="fa fa-facebook"></i></a>-->
-<!--        <a href="#" class="google-plus"><i class="fa fa-google-plus"></i></a>-->
-<!--        <a href="#" class="linkedin"><i class="fa fa-linkedin"></i></a>-->
-<!--        <a href="#" class="instagram"><i class="fa fa-instagram"></i></a>-->
-<!--      </div>-->
-<!--    </div>-->
-<!--  </section>-->
-
-<!--==========================
-  Header
-============================-->
 <header id="header">
     <div class="container">
 
@@ -92,7 +68,7 @@
 <!--==========================
     Page Banner Section
   ============================-->
-<section id="innerBanner">
+<section id="innerBanner" style="background-color: #00a3d1">
     <div class="inner-content">
         <h2><span>{{.content.Title}}</span><br>欢迎来到宝智达冷链</h2>
         <div>
@@ -108,9 +84,6 @@
     <div class="container">
         <div class="section-header">
             <h2>部分合作案例</h2>
-            <!--                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores quae porro consequatur aliquam,-->
-            <!--                    incidunt fugiat culpa esse aute nulla. duis fugiat culpa esse aute nulla ipsum velit export irure-->
-            <!--                    minim illum fore</p>-->
         </div>
         <div class="owl-carousel clients-carousel">
             {{range $index,$exam:=.example}}
@@ -125,8 +98,7 @@
 <footer id="footer">
     <div class="container">
         <div class="copyright">
-            Copyright &copy; 2018.Company name All rights reserved.<a target="_blank"
-                                                                      href="http://sc.chinaz.com/moban/">&#x7F51;&#x9875;&#x6A21;&#x677F;</a>
+            Copyright &copy; 2018.Company name All rights reserved.<a target="_blank" href="http://sc.chinaz.com/moban/">&#x7F51;&#x9875;&#x6A21;&#x677F;</a>
         </div>
         <div class="credits">
         </div>
@@ -146,8 +118,6 @@
 <script src="../static/lib/owlcarousel/owl.carousel.min.js"></script>
 <script src="../static/lib/magnific-popup/magnific-popup.min.js"></script>
 <script src="../static/lib/sticky/sticky.js"></script>
-<script src="contact/jqBootstrapValidation.js"></script>
-<script src="contact/contact_me.js"></script>
 <script src="../static/js/main.js"></script>
 
 </body>

+ 3 - 3
views/index.html

@@ -142,7 +142,7 @@
                     {{end}}
                 </div>
                 <div class="div2 col-6" style="width: 300px;height: auto">
-                    <img src="https://ts1.cn.mm.bing.net/th/id/R-C.7f83c191192defcd927bc9ec7b871de6?rik=%2fZCG9Ijrvtj1zQ&riu=http%3a%2f%2f24461182.s21i.faiusr.com%2f2%2fABUIABACGAAgirvb9wUorIHgiwIwnhQ47A4!700x700.jpg&ehk=7JqIISwbE048OAnWpY3m7VL5qRA0YfiGo7d2uqNL4gw%3d&risl=&pid=ImgRaw&r=0"
+                    <img src="https://ts1.cn.mm.bing.net/th/id/R-C.adaca9eef98172ce4fbb1c2f36405cf6?rik=So40VJkhm3qAxQ&riu=http%3a%2f%2fimg.juimg.com%2ftuku%2fyulantu%2f120417%2f6597-12041F9233979.jpg&ehk=Q7ZmO7gl0UOGFRlkiETxxrZrML6olvsSJ%2fuAINaNNeY%3d&risl=&pid=ImgRaw&r=0"
                          class="img-fluid" alt="">
                 </div>
                 <button class="btn btn-outline-primary"  style="margin-top: 40px;" onclick="location.href='/services/1'">了解更多服务</button>
@@ -243,8 +243,8 @@
 <footer id="footer">
     <div class="container">
         <div class="copyright">
-            Copyright &copy; 2018.Company name All rights reserved.<a target="_blank"
-                                                                      href="http://sc.chinaz.com/moban/">&#x7F51;&#x9875;&#x6A21;&#x677F;</a>
+            © 版权所有 2024 宝智达科技有限公司 <a target="_blank"
+                                                                      href="https://beian.miit.gov.cn/">黔ICP备2022006612号</a>
         </div>
         <div class="credits">
         </div>