增加案例页面的错误处理机制

This commit is contained in:
zhcnyuyang 2025-05-11 13:36:25 +08:00
parent 1288dffb3c
commit 4b82c6b546
2 changed files with 19 additions and 8 deletions

View File

@ -110,6 +110,10 @@ export default {
<style scoped lang="scss"> <style scoped lang="scss">
@import "src/publicstyle.scss"; @import "src/publicstyle.scss";
#bannercontentfill{
}
#passagebanner{ #passagebanner{
@include media-breakpoint-between(xs, md) { @include media-breakpoint-between(xs, md) {
background-image: url('/ExamplesRes/Examplesbanner_wep.png'); background-image: url('/ExamplesRes/Examplesbanner_wep.png');

View File

@ -2,21 +2,21 @@
<!--<div class="pageroot" style="background-color: white;">--> <!--<div class="pageroot" style="background-color: white;">-->
<div v-if="this.error==null" id="examplelist"> <div v-if="this.error==null" id="examplelist">
<div id="typegrid"> <div id="typegrid">
<router-link to="/Examples" style="text-decoration: none;"> <a href="/Examples" style="text-decoration: none;">
<div class="typebar" <div class="typebar"
:class="{ :class="{
active: (!$route.query.type || $route.query.type === '')}"> active: (!$route.query.type || $route.query.type === '')}">
全部 全部
</div> </div>
</router-link> </a>
<router-link v-for="(item, index) in this.types" <a v-for="(item, index) in this.types"
:key="index":to="`/Examples?type=${item}`" :key="index":href="`/Examples?type=${item}`"
style="text-decoration: none;"> style="text-decoration: none;">
<div class="typebar" <div class="typebar"
:class="{ active: $route.fullPath === `/Examples?type=${item}` }"> :class="{ active: $route.fullPath === `/Examples?type=${item}` }">
{{item}} {{item}}
</div> </div>
</router-link> </a>
</div> </div>
<!--列表--> <!--列表-->
<div id="listmain"> <div id="listmain">
@ -86,18 +86,25 @@ export default {
this.error=null; this.error=null;
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
const type = params.get('type'); const type = params.get('type');
let reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage'; console.log('type!',type);
let reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&sort=createdAt:desc';
if(type){ if(type){
reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&filters[example_type]='+type; console.log('type!',type);
reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&filters[example_type]='+type+'&sort=createdAt:desc';
} }
if (this.$route.name != 'Examples'){ if (this.$route.name != 'Examples'){
let reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&pagination[page]=1&pagination[pageSize]=5'; let reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&pagination[page]=1&pagination[pageSize]=5&sort=createdAt:desc';
} }
axios.get(reqarg) axios.get(reqarg)
.then(response =>{ .then(response =>{
const resp = response.data; const resp = response.data;
if(resp.meta.pagination.pageCount==0){
window.location.href = '/Examples';
console.log('turn');
}
if (resp && Array.isArray(resp.data)) { if (resp && Array.isArray(resp.data)) {
this.titles = resp.data; this.titles = resp.data;
console.log('reqarg',reqarg);
if(this.titles.length==0){ if(this.titles.length==0){
this.error = "返回的 JSON 对象中不存在 'data' 数组"; this.error = "返回的 JSON 对象中不存在 'data' 数组";
} }