Переглянути джерело

8-2分类管理页面搭建

Home 4 роки тому
батько
коміт
f96e9a6483

+ 28 - 0
app/admin/controller/Category.php

@@ -0,0 +1,28 @@
+<?php
+
+
+namespace app\admin\controller;
+
+
+use think\facade\View;
+
+class Category extends AdminBase
+{
+    /**
+     * @return string
+     * @throws \Exception
+     */
+    public function index()
+    {
+        return View::fetch();
+    }
+
+    /**
+     * @return string
+     * @throws \Exception
+     */
+    public function add()
+    {
+        return View::fetch();
+    }
+}

+ 14 - 14
public/static/admin/page/dialog.html → app/admin/view/category/add.html

@@ -6,8 +6,8 @@
           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
     <meta http-equiv="X-UA-Compatible" content="ie=edge">
     <title>添加商品分类</title>
-    <link rel="stylesheet" href="../lib/layui-v2.5.4/css/layui.css" media="all">
-    <link rel="stylesheet" href="../css/public.css" media="all">
+    <link rel="stylesheet" href="{__STATIC_PATH}admin/lib/layui-v2.5.4/css/layui.css" media="all">
+    <link rel="stylesheet" href="{__STATIC_PATH}admin/css/public.css" media="all">
 </head>
 <body>
 <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
@@ -37,9 +37,9 @@
         </div>
     </div>
 </form>
-<script src="../lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
-<script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
-<script src="../js/common.js" charset="utf-8"></script>
+<script src="{__STATIC_PATH}admin/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
+<script src="{__STATIC_PATH}admin/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
+<script src="{__STATIC_PATH}admin/js/common.js" charset="utf-8"></script>
 <script>
     layui.use(['form','laypage'], function () {
         var form = layui.form;
@@ -87,15 +87,15 @@
         form.on('submit(demo1)', function (data) {
             console.log(data.field, '最终的提交信息')
             let url = '';
-            layObj.post(url,data,function (res) {
-
-            });
-            // $ajax({
-            //     url: '{:u("admin/add")}?val=' + data.field,
-            //     success: (res) => {
-            //        setTimeout('window.location.reload()',1000);
-            //     }
-            // })
+            // layObj.post(url,data,function (res) {
+            //
+            // });
+            $ajax({
+                url: '{:url("save")}?val=' + data.field,
+                success: (res) => {
+                   setTimeout('window.location.reload()',1000);
+                }
+            })
 
             return false;
         });

+ 12 - 12
public/static/admin/page/classif.html → app/admin/view/category/index.html

@@ -6,8 +6,8 @@
     <meta name="renderer" content="webkit">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
-    <link rel="stylesheet" href="../lib/layui-v2.5.4/css/layui.css" media="all">
-    <link rel="stylesheet" href="../css/public.css" media="all">
+    <link rel="stylesheet" href="{__STATIC_PATH}admin/lib/layui-v2.5.4/css/layui.css" media="all">
+    <link rel="stylesheet" href="{__STATIC_PATH}admin/css/public.css" media="all">
     <style>
         .inoutCls {
             height: 22px;
@@ -116,9 +116,9 @@
     </div>
 
 </div>
-<script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
-<script src="../lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
-<script src="../js/common.js?v5" charset="utf-8"></script>
+<script src="{__STATIC_PATH}admin/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
+<script src="{__STATIC_PATH}admin/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
+<script src="{__STATIC_PATH}admin/js/common.js?v5" charset="utf-8"></script>
 <!-- 注意:如果你直接复制所有代码到本地,上述js路径需要改成你本地的 -->
 <script>
     layui.use(['form', 'laypage'], function () {
@@ -134,7 +134,7 @@
 
         // 添加 分类
         $('.add').on('click', function () {
-            layObj.dialog('dialog.html')
+            layObj.dialog("{:url('add')}")
         });
 
         //监听状态 更改
@@ -144,7 +144,7 @@
             let id = obj.othis.parent().attr('data-id');
             let status = obj.elem.checked ? 1 : 0;
             $.ajax({
-                url: '{:u("admin/change")}?id=' + id + '&status=' + status,
+                url: '{:url("admin/change")}?id=' + id + '&status=' + status,
                 success: (res) => {
 
                 }
@@ -161,14 +161,14 @@
             if (!name && type == 3) { // 演示 应该放到修改回调中  进行处理
                 return $(that).parent().remove()
             }
-            let   url = '{:u("admin/edit")}?id=' + id + '&name=' + name
+            let   url = '{:url("admin/edit")}?id=' + id + '&name=' + name
             layObj.get(url,  (res) =>{
                 if (name && res) {
                     $(that).val(name)
                 }
             })
             $.ajax({
-                url: '{:u("admin/edit")}?id=' + id + '&name=' + name,
+                url: '{:url("admin/edit")}?id=' + id + '&name=' + name,
                 success(res) {
                     if (name && res) {
                         $(that).val(name)
@@ -188,7 +188,7 @@
                 msg = '二';
             }
             layObj.box(`是否删除${msg}级分类`, () => {
-                let   url = '{:u("admin/del")}?id=' + id
+                let   url = '{:url("admin/del")}?id=' + id
                 layObj.get(url,  (res) =>{
                     $(this).parent().remove()
                 })
@@ -203,8 +203,8 @@
             if(!val){
                 return;
             }
-            // let url = '{:u("admin/sort")}?id=' + id + '&sort='+val;
-            let url = 'http:www.baidu.com';
+            let url = '{:url("admin/sort")}?id=' + id + '&sort='+val;
+            // let url = 'http:www.baidu.com';
             layObj.get(url,function (res) {
                 console.log(res, 'sort');
             })

+ 1 - 1
public/static/admin/api/init.json

@@ -18,7 +18,7 @@
       "child": [
         {
           "title": "分类管理",
-          "href": "page/classif.html",
+          "href": "/admin/category",
           "icon": "fa fa-th-large",
           "target": "_self"
         },