feat: 优化组件导入与样式调整

- 在多个组件中将 require 替换为 import,提升代码可读性和一致性。
- 在 App.vue 中添加分类树的 API 请求,优化分类数据的加载逻辑。
- 更新样式以适配 Element Plus 组件,确保界面一致性。
- 删除不再使用的样式文件,简化项目结构。
This commit is contained in:
田香琪
2026-07-07 19:50:07 +08:00
parent cc86430ea4
commit 6b61b86585
42 changed files with 303 additions and 1375 deletions

View File

@@ -23,6 +23,7 @@
</template>
<script>
import { getCategoryTree } from "@/api/goods.js";
export default {
data() {
@@ -40,10 +41,32 @@ export default {
this.init();
},
methods: {
loadCategoryFromCache() {
try {
const raw = localStorage.getItem("category");
if (!raw) {
return null;
}
const parsed = JSON.parse(raw);
return Array.isArray(parsed) ? parsed : null;
} catch {
return null;
}
},
applyCategoryList(category) {
if (!Array.isArray(category)) {
this.categoryList = [];
return;
}
category.forEach((item) => {
item.___type = "category";
});
this.categoryList = category;
},
// 点击一级
handleClickChild(item, index) {
this.parentIndex = index;
this.secondLevel = item.children;
this.secondLevel = item.children || [];
item.___type = "category";
item.allId = item.id;
@@ -51,8 +74,6 @@ export default {
this.thirdIndex = '';
this.thirdLevel = []
this.$emit("selected", [item]);
// 点击第一级的时候默认显示第二级第一个
// this.handleClickSecondChild(item.children, 0);
},
// 点击二级
handleClickSecondChild(second, index) {
@@ -60,10 +81,9 @@ export default {
second.allId = `${second.parentId},${second.id}`
this.secondIndex = index;
this.thirdLevel = second.children;
this.thirdLevel = second.children || [];
this.thirdIndex = '';
this.$emit("selected", [second]);
// this.handleClickthirdChild(second.children[0], 0);
},
// 点击三级
handleClickthirdChild(item, index) {
@@ -73,21 +93,17 @@ export default {
this.thirdIndex = index;
},
init() {
const loadCategory = () => {
const category = JSON.parse(localStorage.getItem("category"));
if (!Array.isArray(category)) {
return;
}
category.forEach((item) => {
item.___type = "category";
});
this.categoryList = category;
};
loadCategory();
if (!this.categoryList.length) {
setTimeout(loadCategory, 3000);
const cached = this.loadCategoryFromCache();
if (cached) {
this.applyCategoryList(cached);
return;
}
getCategoryTree().then((res) => {
if (res.success && Array.isArray(res.result)) {
localStorage.setItem("category", JSON.stringify(res.result));
this.applyCategoryList(res.result);
}
});
},
},
};

View File

@@ -3,10 +3,12 @@ import category from "./category.vue";
import pages from "./pages.vue";
import goods from "../goods-dialog.vue";
import other from "./other.vue";
import shops from "./shops.vue";
export default {
category: markRaw(category),
goods: markRaw(goods),
other: markRaw(other),
pages: markRaw(pages),
shops: markRaw(shops),
};

View File

@@ -44,12 +44,12 @@
</div>
</div>
<el-pagination
v-model:current-page="params.pageNumber"
class="pageration"
size="small"
layout="total, prev, pager, next, jumper"
:total="total"
:page-size="params.pageSize"
:current-page="params.pageNumber"
@current-change="changePageSize"
/>
</div>