提交 a789c36c authored 作者: 王鹏飞's avatar 王鹏飞

chore: update

上级 76d66045
差异被折叠。
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
"dependencies": { "dependencies": {
"@vueuse/core": "^9.4.0", "@vueuse/core": "^9.4.0",
"axios": "^1.1.3", "axios": "^1.1.3",
"element-plus": "^2.2.19", "element-plus": "^2.2.21",
"pinia": "^2.0.23", "pinia": "^2.0.24",
"qrcode.vue": "^3.3.3", "qrcode.vue": "^3.3.3",
"swiper": "^8.4.4", "swiper": "^8.4.4",
"vue": "^3.2.41", "vue": "^3.2.45",
"vue-router": "^4.1.6" "vue-router": "^4.1.6"
}, },
"devDependencies": { "devDependencies": {
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
"sass": "^1.55.0", "sass": "^1.55.0",
"typescript": "~4.7.4", "typescript": "~4.7.4",
"unplugin-auto-import": "^0.11.4", "unplugin-auto-import": "^0.11.4",
"vite": "^3.2.0", "vite": "^3.2.4",
"vue-tsc": "^1.0.9" "vue-tsc": "^1.0.9"
} }
} }
...@@ -8,12 +8,13 @@ const props = defineProps({ ...@@ -8,12 +8,13 @@ const props = defineProps({
type: String type: String
} }
}) })
const courseListAll: any = ref([]) const courseListAll = computed<any>(() => {
if (props.type === '') { if (props.type) {
courseListAll.value = JSON.parse(JSON.stringify(props.courseList)) props.courseList?.filter((item: any) => item.category === props.type)
} else { } else {
courseListAll.value = props.courseList?.filter((item: any) => item.category === props.type) return props.courseList
} }
})
</script> </script>
<template> <template>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import CourseList from '../components/CourseList.vue' import CourseList from '../components/CourseList.vue'
import { useShopStore } from '@/stores/shop' import { useShopStore } from '@/stores/shop'
const { filters, shopList } = useShopStore() const shopStore = useShopStore()
const handleTabClick = (tab: any) => { const handleTabClick = (tab: any) => {
if (tab.index === '4') { if (tab.index === '4') {
window.open('https://prp.ezijing.com') window.open('https://prp.ezijing.com')
...@@ -17,11 +17,11 @@ const handleTabClick = (tab: any) => { ...@@ -17,11 +17,11 @@ const handleTabClick = (tab: any) => {
<div class="shop_con"> <div class="shop_con">
<div class="con_tab"> <div class="con_tab">
<el-tabs class="my-tabs" @tab-click="handleTabClick"> <el-tabs class="my-tabs" @tab-click="handleTabClick">
<el-tab-pane v-for="(item, index) in filters" :key="index" lazy> <el-tab-pane v-for="(item, index) in shopStore.filters" :key="index" lazy>
<template #label> <template #label>
{{ item.label }} {{ item.label }}
</template> </template>
<CourseList :type="item.value" :courseList="shopList" :key="index" /> <CourseList :type="item.value" :courseList="shopStore.shopList" />
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
......
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
// import { useUserStore } from './user' import { useUserStore } from './user'
// const { courses } = useUserStore()
interface ShopFilter { interface ShopFilter {
label: string label: string
value: string value: string
...@@ -8,50 +7,44 @@ interface ShopFilter { ...@@ -8,50 +7,44 @@ interface ShopFilter {
} }
type ShopListItem = Record<string, any> type ShopListItem = Record<string, any>
interface State { export const useShopStore = defineStore('shop', () => {
filters: ShopFilter[] const route = useRoute()
list: ShopListItem[] const userStore = useUserStore()
} // 筛选列表
const filters = ref<ShopFilter[]>((window as any).SHOP.SHOP_FILTERS)
// 商品列表
const list = ref<ShopListItem[]>((window as any).SHOP.SHOP_LIST)
export const useShopStore = defineStore({ // 计算后的商品列表,是否购买
id: 'shop', const shopList = computed<ShopListItem[]>(() => {
state: (): State => ({ return list.value.map(item => {
filters: (window as any).SHOP.SHOP_FILTERS, // 筛选列表 const isBuy = !!userStore.courses.find((course: any) => course.course_id === item.course_id)
list: (window as any).SHOP.SHOP_LIST // 商品列表 return { ...item, isBuy }
}),
getters: {
shopList({ list }) {
return list.map(item => {
// const { courses } = useUserStore()
const courses = JSON.parse(localStorage.getItem('courses') as string)
item.isBuy = !!courses.find((course: any) => course.course_id === item.course_id)
return item
}) })
}, })
shopItem(): ShopListItem | undefined {
const route = useRoute() // 详情页面的单个商品
const found = this.shopList.find(item => item.id === route.params.id) const shopItem = computed(() => {
const found = shopList.value.find(item => item.id === route.params.id)
if (found) { if (found) {
found.course_list = found.course_list =
found.child_ids && found.child_ids.length found.child_ids && found.child_ids.length
? found.child_ids.map((id: string) => this.shopList.find(item => item.id === id)) ? found.child_ids.map((id: string) => shopList.value.find(item => item.id === id))
: this.shopList.filter(item => item.child_ids?.includes(found.id)) : shopList.value.filter(item => item.child_ids?.includes(found.id))
} }
return found return found
}, })
shopRelatedList(): ShopListItem[] {
return this.shopList.filter((item: ShopListItem) => item.category !== this.shopItem?.category) // 相关推荐商品列表
}, const shopRelatedList = computed(() => {
shopRelatedListOther(): ShopListItem[] { return shopList.value.filter(item => item.category !== shopItem.value?.category)
return this.shopList.filter( })
(item: ShopListItem) => item.category === this.shopItem?.category && item.id !== this.shopItem?.id
const shopRelatedListOther = computed(() => {
return shopList.value.filter(
(item: ShopListItem) => item.category === shopItem.value?.category && item.id !== shopItem.value?.id
) )
} })
},
actions: { return { filters, list, shopList, shopItem, shopRelatedList, shopRelatedListOther }
// async getShopList() {
// const shop = await import('https://webapp-pub.ezijing.com/project_online/fi/shop.js')
// console.log(shop)
// }
}
}) })
...@@ -10,7 +10,7 @@ export const useUserStore = defineStore({ ...@@ -10,7 +10,7 @@ export const useUserStore = defineStore({
id: 'user', id: 'user',
state: (): State => ({ state: (): State => ({
user: null, user: null,
courses: [] || JSON.parse(localStorage.getItem('courses') as string) courses: []
}), }),
getters: { getters: {
isLogin: state => !!state.user, isLogin: state => !!state.user,
...@@ -28,7 +28,6 @@ export const useUserStore = defineStore({ ...@@ -28,7 +28,6 @@ export const useUserStore = defineStore({
const res = await getUser() const res = await getUser()
try { try {
this.courses = await getBuyShop() this.courses = await getBuyShop()
localStorage.setItem('courses', JSON.stringify(this.courses))
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论