From 0c9c441fdc53b62bf6b8782f3476953aaf5f845a Mon Sep 17 00:00:00 2001 From: yaosen <741606767@qq.com> Date: Thu, 27 Jun 2024 19:53:53 +0800 Subject: [PATCH] a --- admin/src/layout/components/Navbar.vue | 4 +- admin/src/views/qa/city.vue | 143 +++++++++++++++++- admin/src/views/qa/qa.vue | 47 +++++- .../app/admin/controller/QaCityController.php | 70 +++++++++ service/app/admin/controller/QaController.php | 19 ++- service/app/middleware/adminAuth.php | 3 +- service/app/model/Qas.php | 5 + 7 files changed, 273 insertions(+), 18 deletions(-) create mode 100644 service/app/admin/controller/QaCityController.php diff --git a/admin/src/layout/components/Navbar.vue b/admin/src/layout/components/Navbar.vue index cf8da149..1a54169e 100644 --- a/admin/src/layout/components/Navbar.vue +++ b/admin/src/layout/components/Navbar.vue @@ -303,7 +303,7 @@ export default { }) }, beforeAvatarUpload(file) { - const isJPG = file.type === 'image/jpeg' + /*const isJPG = file.type === 'image/jpeg' const isLt2M = file.size / 1024 / 1024 < 2 if (!isJPG) { @@ -312,7 +312,7 @@ export default { if (!isLt2M) { this.$message.error('上传头像图片大小不能超过 2MB!') } - return isJPG && isLt2M + return isJPG && isLt2M*/ } } } diff --git a/admin/src/views/qa/city.vue b/admin/src/views/qa/city.vue index 51760449..0bb8e819 100644 --- a/admin/src/views/qa/city.vue +++ b/admin/src/views/qa/city.vue @@ -1,11 +1,144 @@ - - - diff --git a/admin/src/views/qa/qa.vue b/admin/src/views/qa/qa.vue index 65d5cd40..83ccfda3 100644 --- a/admin/src/views/qa/qa.vue +++ b/admin/src/views/qa/qa.vue @@ -12,7 +12,7 @@ - + @@ -33,7 +33,17 @@ - + + + + + @@ -41,6 +51,14 @@ + + + (只接受压缩包) + + + + (只接受压缩包) + @@ -53,7 +71,17 @@ - + + + + + @@ -96,13 +124,15 @@ export default { dialogCreate: false, dialogEdit: false, item: {}, - anchors: {} + anchors: {}, + getQaCitys: {} } }, created() { this.listQuery.status = this.$route.query.status || null this.listQuery.content = this.$route.query.content || null this.getQa() + this.getQaCity() }, methods: { getQa() { @@ -116,7 +146,7 @@ export default { }) }, onAdd() { - this.anchors = { sort: 0 } // 初始化时默认排序值为0 + this.anchors = {} // 初始化时默认排序值为0 this.dialogCreate = true }, onEdit(item) { @@ -142,6 +172,13 @@ export default { }).catch(() => { }) }, + getQaCity(){ + this.$axios.post('/admin/qacity/getQaCity').then(response => { + this.getQaCitys = response.data + this.getQa() + }).catch(() => { + }) + }, updateSort(item) { this.$axios.post('/admin/qa/editQa', { id: item.id, sort: item.sort }).then(() => { this.getQa() diff --git a/service/app/admin/controller/QaCityController.php b/service/app/admin/controller/QaCityController.php new file mode 100644 index 00000000..ce6bcdf9 --- /dev/null +++ b/service/app/admin/controller/QaCityController.php @@ -0,0 +1,70 @@ +get('limit',10)); + + return $this->success($list); + } + + public function getQaCity(Request $request) + { + $list = QaCitys::order('city_id desc')->select(); + + return $this->success($list); + } + + public function addQaCity(Request $request) + { + $post = $request->post(); + if (empty($post['city_name'])) return $this->error(2001, 'city_name data cannot be empty!'); + + try { + $data = QaCitys::create($post); + } catch (\Exception $e) { + return $this->error(2002, $e->getMessage()); + } + return $this->success($data); + } + + public function editQaCity(Request $request) + { + $post = $request->post(); + if (empty($post['city_id'])) return $this->error(2001, 'id data cannot be empty!'); + $city_id = $post['city_id']; + unset($post['city_id']); + + try { + $data = QaCitys::where('city_id',$city_id)->update($post); + } catch (\Exception $e) { + return $this->error(2002, $e->getMessage()); + } + return $this->success($data); + } + + public function delQaCity(Request $request) + { + $city_id = $request->post('city_id'); + if (empty($city_id)) return $this->error(2001, 'city_id data cannot be empty!'); + try { + $data = QaCitys::where('city_id',$city_id)->delete(); + } catch (\Exception $e) { + return $this->error(2002, $e->getMessage()); + } + return $this->success($data); + } +} \ No newline at end of file diff --git a/service/app/admin/controller/QaController.php b/service/app/admin/controller/QaController.php index 3e607b57..89270ff9 100644 --- a/service/app/admin/controller/QaController.php +++ b/service/app/admin/controller/QaController.php @@ -4,6 +4,7 @@ namespace app\admin\controller; use app\model\QaCitys; use app\model\Qas; +use support\Log; use support\Request; class QaController extends base @@ -11,9 +12,17 @@ class QaController extends base public function getQaList(Request $request) { $city_id = $request->get('city_id'); - if (empty($city_id)) return $this->error(2001, 'city_id data cannot be empty!'); + $keyword = $request->get('keyword'); - $list = Qas::where(['status'=>1,'city_id'=>$city_id])->fieldRaw('title,content')->select(); + $list = Qas::order('id decs'); + + if (!empty($city_id)){ + $list = $list->where(['status' => 1, 'city_id' => $city_id]); + } + if (!empty($keyword)){ + $list = $list->whereRaw("title LIKE ? OR content LIKE ?", ['%'.$keyword.'%', '%'.$keyword.'%']); + } + $list = $list->paginate($request->get('limit',10)); return $this->success($list); } @@ -29,7 +38,7 @@ class QaController extends base $title = $request->get('title'); $status = $request->get('status'); - $list = Qas::order('create_time desc'); + $list = Qas::with('qaCitys')->order('create_time desc'); if (!empty($title)){ $list = $list->where('title','like','%'.$title.'%'); @@ -47,7 +56,7 @@ class QaController extends base $id = $request->get('id'); if (empty($id)) return $this->error(2001, 'id data cannot be empty!'); - $data = Qas::where('status',1)->fieldRaw('id,city_name,title,content')->find(); + $data = Qas::where('status',1)->find(); return $this->success($data); } @@ -55,7 +64,7 @@ class QaController extends base public function addQa(Request $request) { $post = $request->post(); - if (empty($post['city_name'])) return $this->error(2001, 'city_name data cannot be empty!'); + if (empty($post['city_id'])) return $this->error(2001, 'city_id data cannot be empty!'); if (empty($post['title'])) return $this->error(2001, 'title data cannot be empty!'); if (empty($post['content'])) return $this->error(2001, 'content data cannot be empty!'); diff --git a/service/app/middleware/adminAuth.php b/service/app/middleware/adminAuth.php index ec8759e2..226e6da4 100644 --- a/service/app/middleware/adminAuth.php +++ b/service/app/middleware/adminAuth.php @@ -19,7 +19,8 @@ class adminAuth implements MiddlewareInterface if($path) { //白名单 $url = [ - '/admin/login' + '/admin/login', + 'admin/index/avatar' ]; if(in_array($path, $url)) { return $next($request); diff --git a/service/app/model/Qas.php b/service/app/model/Qas.php index 99a7422d..e0c92dcd 100644 --- a/service/app/model/Qas.php +++ b/service/app/model/Qas.php @@ -5,4 +5,9 @@ namespace app\model; class Qas extends base { + public function qaCitys() + { + return $this->hasOne(QaCitys::class,'city_id','city_id'); + } + } \ No newline at end of file