diff --git a/admin/src/api/esg.js b/admin/src/api/esg.js new file mode 100644 index 0000000..40e8b09 --- /dev/null +++ b/admin/src/api/esg.js @@ -0,0 +1,16 @@ +import ajax from "@/utils/request"; + +export const getEsgList = async (params) => + ajax(`/esg/getEsgList`, "POST", params); + +export const getEsg = async (id) => + ajax(`/esg/getEsg`, "GET", { id }); + +export const deleteEsg = async (id) => + ajax(`/esg/deleteEsg`, "GET", { id }); + +export const updateEsg = async (params) => + ajax(`/esg/updateEsg`, "POST", params); + +export const addEsg = async (params) => + ajax(`/esg/addEsg`, "POST", params); diff --git a/admin/src/layouts/menu/index.vue b/admin/src/layouts/menu/index.vue index 92a1037..80e7f1b 100644 --- a/admin/src/layouts/menu/index.vue +++ b/admin/src/layouts/menu/index.vue @@ -84,6 +84,10 @@ const menuData = ([ { title: "公司活動", path: "/news/activity", + }, + { + title: "ESG", + path: "/news/esg", } ], }, diff --git a/admin/src/layouts/tabs/index.vue b/admin/src/layouts/tabs/index.vue index 06a58ad..e4c7b7c 100644 --- a/admin/src/layouts/tabs/index.vue +++ b/admin/src/layouts/tabs/index.vue @@ -62,7 +62,7 @@ const handleCloseAll = () => { }; const addTab = () => { - if (route.path === "/login" || route.path === "/news/list/form" || route.path === "/product/list/form") return; + if (route.path === "/login" || route.path === "/news/list/form" || route.path === "/product/list/form" || route.path === "/news/esg/form") return; if (route.path) { tabsStore.addTab({ path: route.path, diff --git a/admin/src/pages/News/esg/components/Form.vue b/admin/src/pages/News/esg/components/Form.vue new file mode 100644 index 0000000..15a5f12 --- /dev/null +++ b/admin/src/pages/News/esg/components/Form.vue @@ -0,0 +1,137 @@ + + + + + \ No newline at end of file diff --git a/admin/src/pages/News/esg/form.vue b/admin/src/pages/News/esg/form.vue new file mode 100644 index 0000000..38a30bb --- /dev/null +++ b/admin/src/pages/News/esg/form.vue @@ -0,0 +1,156 @@ + + + + + \ No newline at end of file diff --git a/admin/src/pages/News/esg/index.vue b/admin/src/pages/News/esg/index.vue new file mode 100644 index 0000000..1bb9a59 --- /dev/null +++ b/admin/src/pages/News/esg/index.vue @@ -0,0 +1,176 @@ + + + + + \ No newline at end of file diff --git a/admin/src/router/index.js b/admin/src/router/index.js index 956fa96..bee9e02 100644 --- a/admin/src/router/index.js +++ b/admin/src/router/index.js @@ -84,6 +84,22 @@ let routes = [ }, component: () => import("../pages/News/list/form.vue"), }, + { + path: "/news/esg", + name: "ESG", + meta: { + title: "ESG", + }, + component: () => import("../pages/News/esg/index.vue"), + }, + { + path: "/news/esg/form", + name: "EsgForm", + meta: { + title: "ESG表單", + }, + component: () => import("../pages/News/esg/form.vue"), + }, { path: "/news/activity", name: "newsActivity", diff --git a/app/app/adminapi/controller/EsgController.php b/app/app/adminapi/controller/EsgController.php new file mode 100644 index 0000000..f403b8d --- /dev/null +++ b/app/app/adminapi/controller/EsgController.php @@ -0,0 +1,126 @@ +post(); + $page = isset($param['page']) ? $param['page'] : 1; + $pageSize = isset($param['pageSize']) ? $param['pageSize'] : 10; + $search = isset($param['search']) ? $param['search'] : []; + + $where = [ + ]; + + $list = Db::name('esg') + ->where($where) + ->order('create_time', 'desc') + ->page($page, $pageSize) + ->select() + ->toArray(); + + $total = Db::name('esg') + ->where($where) + ->count(); + + foreach($list as $key => $val){ + } + + $result = [ + 'list' => $list, + 'total' => $total + ]; + + return $this->Success($result); + } + + public function addEsg(Request $request){ + $params = $request->post(); + + $data = [ + 'title' => isset($params['title'])?$params['title']:'', + 'content' => isset($params['content'])?$params['content']:'', + 'create_time' => date('Y-m-d H:i:s',time()) + ]; + + try{ + $id = Db::name('esg')->insertGetId($data); + + AdminLog( $this->uid , '新增產業動態 ' . $id); + + return $this->Success('操作成功'); + }catch(\Exception $e){ + AdminLog( $this->uid , '新增產業動態失敗'); + + return $this->Error('操作失敗:'. $e->getMessage()); + } + } + + public function deleteEsg(Request $request){ + $id = $request->get('id'); + + try{ + $admin_name = getNameById('admin','username',$id); + + $result = Db::name('esg') + ->where('id',$id) + ->delete(); + + AdminLog($this->uid, '刪除管理員 '. $admin_name); + return $this->Success('操作成功'); + }catch(\Exception $e){ + AdminLog($this->uid, '刪除管理員'.$admin_name.'失敗'); + return $this->Error('操作失敗'); + } + } + + public function getEsg(Request $request){ + $id = $request->get('id'); + + $user = Db::name('esg') + ->where('id',$id) + ->find(); + + if(!$user){ + return $this->Error('資料不存在'); + } + + unset($user['password']); + + $result = $user; + + return $this->Success($result); + } + + public function updateEsg(Request $request){ + $params = $request->post(); + + $data = [ + 'title' => isset($params['title'])?$params['title']:'', + 'content' => isset($params['content'])?$params['content']:'', + 'update_time' => date('Y-m-d H:i:s',time()) + ]; + + try{ + $result = Db::name('esg') + ->where('id',$params['id']) + ->update($data); + + AdminLog($this->uid, '修改產業動態 [' . $params['id'] .']'); + + return $this->Success('操作成功'); + }catch(\Exception $e){ + + AdminLog($this->uid, '修改產業動態 [' . $params['id'] . '] 失敗'); + + return $this->Error('操作失敗:'. $e->getMessage()); + } + } + +} diff --git a/app/app/appapi/controller/ProductController.php b/app/app/appapi/controller/ProductController.php index c66de64..fc02267 100644 --- a/app/app/appapi/controller/ProductController.php +++ b/app/app/appapi/controller/ProductController.php @@ -73,4 +73,26 @@ class ProductController extends BaseController return $this->Success($result); } + public function searchProduct(Request $request) + { + $param = $request->get(); + + $list = Db::name('product') + ->where('lang',$param['lang']) + ->where('name|description|content','like','%'.$param['keyword'].'%') + ->order('sort_order', 'asc') + ->order('id', 'asc') + ->select() + ->toArray(); + + + // foreach($list as $key => $val){ + // $list[$key]['imageurl1'] = getUrl().$val['imageurl1']; + // $list[$key]['imageurl2'] = getUrl().$val['imageurl2']; + // } + + $result = $list; + + return $this->Success($result); + } } diff --git a/app/app/appapi/controller/SocialController.php b/app/app/appapi/controller/SocialController.php index 207a4fa..f1a485e 100644 --- a/app/app/appapi/controller/SocialController.php +++ b/app/app/appapi/controller/SocialController.php @@ -110,4 +110,58 @@ class SocialController extends BaseController return $this->Success($result); } + + public function getEsgList(Request $request) + { + $param = $request->post(); + + $page = isset($param['page']) ? $param['page'] : 1; + $pageSize = isset($param['pageSize']) ? $param['pageSize'] : 10; + $search = isset($param['search']) ? $param['search'] : []; + + $where = []; + + $list = Db::name('esg') + ->where($where) + ->where('lang', $param['lang']) + ->order('create_time', 'desc') + ->page($page, $pageSize) + ->select() + ->toArray(); + + $total = Db::name('esg') + ->where($where) + ->where('lang', $param['lang']) + ->count(); + + // foreach($list as $key => $val){ + // } + + $result = [ + 'list' => $list, + 'total' => $total + ]; + + return $this->Success($result); + } + + public function getEsg(Request $request) + { + $param = $request->get(); + + if (empty($param['id'])) { + return $this->Error('參數錯誤'); + } + + $where = []; + + $news = Db::name('esg') + ->where('id', $param['id']) + ->find(); + + $result = $news; + + return $this->Success($result); + } + } diff --git a/web/assets/css/main.css b/web/assets/css/main.css index 494d4b6..9022373 100644 --- a/web/assets/css/main.css +++ b/web/assets/css/main.css @@ -3707,7 +3707,9 @@ textarea.form-control-lg { background-clip: padding-box; border: 1px solid rgba(0, 0, 0, 0.15); border-radius: 0.25rem; + cursor: pointer; } + .dropdown-menu[data-bs-popper] { top: 100%; left: 0; @@ -3717,6 +3719,7 @@ textarea.form-control-lg { .dropdown-menu-start { --bs-position: start; } + .dropdown-menu-start[data-bs-popper] { right: auto; left: 0; diff --git a/web/composables/useMyFetch.js b/web/composables/useMyFetch.js index e302750..97cffbc 100644 --- a/web/composables/useMyFetch.js +++ b/web/composables/useMyFetch.js @@ -12,7 +12,7 @@ export const useMyFetch = (request, method="GET" ,opts={}, headers ={}) => { ...headers, } }; - console.log("options", options.baseURL, request) + let data = { ...opts, lang: locale diff --git a/web/layouts/default.vue b/web/layouts/default.vue index b30a46f..cfed01d 100644 --- a/web/layouts/default.vue +++ b/web/layouts/default.vue @@ -4,8 +4,12 @@ import logoImg from '@/assets/img/logo.png'; import dotCircleImg from '@/assets/img/dotCircle.png'; import useStore from '@/store'; +const localePath = useLocalePath() + const { locale } = useI18n() +const searchKeyword = ref(''); + const navbarToggler = ref(null); const store = useStore(); @@ -26,6 +30,12 @@ const goRoute = (path) => { } router.push(path); } + +const handleSearchSubmit = () => { + if(!searchKeyword.value) return; + router.push(localePath('/products/search/' + searchKeyword.value)); + searchKeyword.value = ''; +}