秦佳浩 2 months ago
commit 090b6fcf85

@ -41,109 +41,111 @@
</view>
</view>
<!-- 子分类 -->
<!-- 这是一个条件渲染的视图元素只有当subCategoryList数组的长度大于0时才会显示 -->
<view v-if="subCategoryList.length"
class="th-cate-con">
<!-- 使用v-for指令循环遍历subCategoryList数组index为当前项的索引thCateItem代表数组中的每个子分类项对象 -->
<block v-for="(thCateItem, index) in subCategoryList"
:key="index">
<!-- 每个子分类的外层视图容器用于包裹子分类相关的内容设置了类名为sub-category -->
<view class="sub-category">
<!-- 子分类具体项的视图容器绑定了点击事件toCatePage并且通过自定义属性传递了子分类相关的ID信息 -->
<view class="sub-category-item"
:data-categoryid="thCateItem.categoryId"
:data-parentid="thCateItem.parentId"
@tap="toCatePage">
<!-- 展示子分类对应的图片通过util.checkFileUrl方法对图片路径进行处理可能是检查路径合法性添加域名等操作并设置了类名为more-pic以及图片的显示模式为widthFixwidthFix模式可以让图片宽度自适应容器宽度高度按比例缩放 -->
<image :src="util.checkFileUrl(thCateItem.pic)"
class="more-pic"
mode="widthFix" />
<!-- 展示子分类的名称通过双括号插值表达式绑定子分类项对象中的categoryName属性来显示具体的名称文本 -->
<text>{{ thCateItem.categoryName }}</text>
</view>
</view>
</block>
</view>
<!-- 当subCategoryList数组长度为0时显示这个视图元素用于给用户提示当前分类下暂无子分类的信息 -->
<view v-else
class="cont-item empty">
该分类下暂无子分类~
</view>
</scroll-view>
<!-- 右侧内容end -->
</view>
</view>
</template>
<script setup>
import util from '@/utils/util.js'
import { ref, onLoad } from 'vue'
import { uni } from '@dcloudio/uni-app'
import { http } from '@/utils/http.js' // http
<script setup>
import util from '@/utils/util.js'
import { ref, onLoad } from 'vue'
import { uni } from '@dcloudio/uni-app'
import { http } from '@/utils/http.js' // http
//
const categoryList = ref([])
//
const subCategoryList = ref([])
//
const categoryImg = ref('')
// ID
const parentId = ref('')
// 0
const selIndex = ref(0)
//
const categoryList = ref([])
//
const subCategoryList = ref([])
//
const categoryImg = ref('')
// ID
const parentId = ref('')
// 0
const selIndex = ref(0)
// -
onLoad(() => {
//
http.request({
url: '/category/categoryInfo',
method: 'GET',
data: {
parentId: ''
}
})
.then(({ data }) => {
categoryImg.value = data[0].pic
categoryList.value = data
getProdList(data[0].categoryId)
parentId.value = categoryList.value[0].categoryId
})
})
// -
onLoad(() => {
//
http.request({
url: '/category/categoryInfo',
method: 'GET',
data: {
parentId: ''
}
})
.then(({ data }) => {
categoryImg.value = data[0].pic
categoryList.value = data
getProdList(data[0].categoryId)
parentId.value = categoryList.value[0].categoryId
})
})
//
const onMenuTab = (e) => {
const index = e.currentTarget.dataset.index
getProdList(categoryList.value[index].categoryId)
parentId.value = categoryList.value[index].categoryId
categoryImg.value = categoryList.value[index].pic
selIndex.value = index
}
//
const onMenuTab = (e) => {
const index = e.currentTarget.dataset.index
getProdList(categoryList.value[index].categoryId)
parentId.value = categoryList.value[index].categoryId
categoryImg.value = categoryList.value[index].pic
selIndex.value = index
}
//
const toSearchPage = () => {
uni.navigateTo({
url: '/pages/search-page/search-page'
})
}
//
const toSearchPage = () => {
uni.navigateTo({
url: '/pages/search-page/search-page'
})
}
//
const getProdList = (categoryId) => {
//
http.request({
url: '/category/categoryInfo',
method: 'GET',
data: {
parentId: categoryId
}
})
.then(({ data }) => {
subCategoryList.value = data
})
}
//
const getProdList = (categoryId) => {
//
http.request({
url: '/category/categoryInfo',
method: 'GET',
data: {
parentId: categoryId
}
})
.then(({ data }) => {
subCategoryList.value = data
})
}
//
const toCatePage = (e) => {
const { categoryid } = e.currentTarget.dataset
uni.navigateTo({
url: `/pages/sub-category/sub-category?parentId=${parentId.value}&categoryId=${categoryid}`
})
}
//
const toCatePage = (e) => {
const { categoryid } = e.currentTarget.dataset
uni.navigateTo({
url: `/pages/sub-category/sub-category?parentId=${parentId.value}&categoryId=${categoryid}`
})
}
</script>
</script>
<style scoped lang="scss">
@import "./category.scss";
</style>
<style scoped lang="scss">
@import "./category.scss";
</style>

Loading…
Cancel
Save