Parcourir la source

refactor: 管理后台代码改成静态模块

runphp il y a 1 semaine
Parent
commit
c6956130af
3 fichiers modifiés avec 58 ajouts et 110 suppressions
  1. 47 0
      frontend/admin/index.js
  2. 11 23
      frontend/admin/views/LimitPurchaseRule.vue
  3. 0 87
      resource/admin/index.vue

+ 47 - 0
frontend/admin/index.js

@@ -0,0 +1,47 @@
+/**
+ * Limit Purchase Module - 限购管理模块
+ */
+
+export default {
+  // 路由配置
+  routes: {
+    path: '/limit_purchase',
+    name: 'LimitPurchaseModule',
+    component: () => import('@/layout/index.vue'),
+    redirect: '/limit_purchase/rule',
+    meta: {
+      title: '限购管理',
+      icon: 'Goods',
+      permission: 'limit_purchase'
+    },
+    children: [
+      {
+        path: 'rule',
+        name: 'LimitPurchaseRule',
+        component: () => import('./views/LimitPurchaseRule.vue'),
+        meta: {
+          title: '限购规则管理',
+          icon: 'List',
+          keepAlive: true
+        }
+      }
+    ]
+  },
+
+  // 菜单配置
+  menus: [
+    {
+      path: '/limit_purchase',
+      title: '限购管理',
+      icon: 'Goods',
+      permission: 'limit_purchase',
+      children: [
+        {
+          path: '/limit_purchase/rule',
+          title: '限购规则管理',
+          icon: 'List'
+        }
+      ]
+    }
+  ]
+}

+ 11 - 23
resource/admin/LimitPurchaseRule.vue → frontend/admin/views/LimitPurchaseRule.vue

@@ -217,14 +217,10 @@
 </template>
 
 <script>
+import request from '@/utils/request'
+
 export default {
   name: 'LimitPurchaseRule',
-  props: {
-    axiosInstance: {
-      type: Object,
-      default: null
-    }
-  },
   data() {
     return {
       // 列表数据
@@ -274,16 +270,10 @@ export default {
     this.fetchProvinces()
   },
   methods: {
-    http() {
-      // 默认用全局 axios,如果父组件传入则优先用父组件的
-      return this.axiosInstance || this.$axios || this.$http
-    },
-
     // 获取省份数据
     async fetchProvinces() {
-      if (!this.http()) return
       try {
-        const response = await this.http().get('/limit_purchase/region/province')
+        const response = await request.get('/limit_purchase/region/province')
         this.provinces = response.data || []
       } catch (e) {
         console.error('获取省份数据失败:', e)
@@ -293,10 +283,9 @@ export default {
 
     // ========== 列表相关 ==========
     async fetchRuleList() {
-      if (!this.http()) return
       this.loading.list = true
       try {
-        const { page } = await this.http().get('/limit_purchase/rule', {
+        const { page } = await request.get('/limit_purchase/rule', {
           params: {
             page: this.pagination.page,
             limit: this.pagination.pageSize
@@ -375,12 +364,12 @@ export default {
 
     submitRuleForm() {
       this.$refs.ruleFormRef.validate(async (valid) => {
-        if (!valid || !this.http()) return
+        if (!valid) return
         this.loading.saveRule = true
         try {
           if (this.ruleForm.id) {
             // 更新:名称 + 是否默认 + 状态 + 限购地区
-            await this.http().put(`/limit_purchase/rule/${this.ruleForm.id}`, {
+            await request.put(`/limit_purchase/rule/${this.ruleForm.id}`, {
               name: this.ruleForm.name,
               is_default: this.ruleForm.is_default,
               status: this.ruleForm.status,
@@ -389,7 +378,7 @@ export default {
             this.$message.success('更新成功')
           } else {
             // 创建:名称 + 是否默认 + 状态 + 限购地区
-            await this.http().post('/limit_purchase/rule', {
+            await request.post('/limit_purchase/rule', {
               name: this.ruleForm.name,
               is_default: this.ruleForm.is_default,
               status: this.ruleForm.status,
@@ -409,13 +398,12 @@ export default {
     },
 
     handleDeleteRule(row) {
-      if (!this.http()) return
       this.$confirm(`确认删除规则「${row.name}」吗?`, '提示', {
         type: 'warning'
       })
         .then(async () => {
           try {
-            const {code,msg} = await this.http().delete(`/limit_purchase/rule/${row.id}`)
+            const {code, msg} = await request.delete(`/limit_purchase/rule/${row.id}`)
             if (code === 0 || code === 200) {
               this.$message.success('删除成功')
               this.fetchRuleList()
@@ -445,7 +433,7 @@ export default {
         const province = this.provinces.find(p => p.name === this.selectedProvince)
         if (province) {
           // 获取城市数据
-          const response = await this.http().get(`/limit_purchase/region/city/${province.code}`)
+          const response = await request.get(`/limit_purchase/region/city/${province.code}`)
           this.cities = response.data || []
         }
       } catch (e) {
@@ -466,7 +454,7 @@ export default {
         if (province) {
           const city = this.cities.find(c => c.name === this.selectedCity)
           if (city) {
-            const response = await this.http().get(`/limit_purchase/region/area/${city.code}`)
+            const response = await request.get(`/limit_purchase/region/area/${city.code}`)
             this.areas = response.data || []
           }
         }
@@ -647,4 +635,4 @@ export default {
   margin-top: 5px;
   margin-bottom: 15px;
 }
-</style>
+</style>

+ 0 - 87
resource/admin/index.vue

@@ -1,87 +0,0 @@
-<template>
-  <div class="limit-purchase-container">
-    <el-container>
-      <el-header height="60px">
-        <el-menu
-          :default-active="activeMenu"
-          mode="horizontal"
-          @select="handleMenuSelect"
-          class="el-menu-horizontal"
-        >
-          <el-menu-item index="limitPurchaseRule">
-            <span>限购规则管理</span>
-          </el-menu-item>
-        </el-menu>
-      </el-header>
-      
-      <el-main>
-        <component 
-          :is="currentComponent" 
-          :axios-instance="axiosInstance" 
-        />
-      </el-main>
-    </el-container>
-  </div>
-</template>
-
-<script>
-import LimitPurchaseRule from './LimitPurchaseRule.vue'
-
-export default {
-  name: 'LimitPurchaseAdmin',
-  components: {
-    LimitPurchaseRule
-  },
-  props: {
-    axiosInstance: {
-      type: Object,
-      default: null
-    }
-  },
-  data() {
-    return {
-      activeMenu: 'limitPurchaseRule'
-    }
-  },
-  computed: {
-    currentComponent() {
-      if (this.activeMenu === 'limitPurchaseRule') {
-        return 'LimitPurchaseRule'
-      }
-      return 'LimitPurchaseRule'
-    }
-  },
-  methods: {
-    handleMenuSelect(key) {
-      this.activeMenu = key
-    }
-  }
-}
-</script>
-
-<style scoped>
-.limit-purchase-container {
-  padding: 0;
-  height: calc(100vh - 120px);
-}
-
-.el-menu-horizontal {
-  height: 60px;
-  font-size: 16px;
-}
-
-.el-header {
-  padding: 0;
-  background-color: #fff;
-  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
-}
-
-.el-main {
-  padding: 30px;
-  background: #fff;
-  margin: 20px;
-  border-radius: 8px;
-  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
-  flex: 1;
-}
-</style>