diff --git a/src/components/ExampleItem.vue b/src/components/ExampleItem.vue index 9dcb263..88e37e4 100644 --- a/src/components/ExampleItem.vue +++ b/src/components/ExampleItem.vue @@ -6,6 +6,64 @@ export default defineComponent({ name: "ExampleItem", components:{ ContactUs + }, + data(){ + return{ + psginfos:[], + psginfo:null, + error:null, + isLoading: false + } + }, + methods:{ + fetchpsginfos:function (){ + this.isLoading=true; + this.error=null; + const params = new URLSearchParams(window.location.search); + const pagecreatedAt = params.get('createdAt'); + this.$axios.get('/api/project-examples?filters[createdAt]='+pagecreatedAt+'&populate[images][sort]=name:asc') + .then(response =>{ + const resp = response.data; + if(resp.meta.pagination.total==0){ + window.location.href = '/Err404'; + } + if (resp && Array.isArray(resp.data)) { + this.psginfos = resp.data; + if(this.psginfos.length==0){ + this.error = "返回的 JSON 对象中不存在 'data' 数组"; + }else{ + this.psginfo=this.psginfos[0]; + let newtitle=this.psginfo.title+'-苏州卡多雷科技有限公司'; + document.title=newtitle; + } + } else { + this.error = "返回的 JSON 对象中不存在 'data' 数组"; + } + }) + .catch(err => { + this.error = '请求失败,请稍后重试'; + }) + .finally(() => { + this.isLoading = false; + }); + if(this.error!=null){ + window.location.href = '/Err404'; + }else{ + + } + } + }, + created() { + // 获取 id 参数 + const params = new URLSearchParams(window.location.search); + const id = params.get('id'); + if (!id) { + // window.location.href = '/Err404'; + } + this.fetchpsginfos(); + }, + mounted() { + } }) @@ -16,9 +74,26 @@ export default defineComponent({ +
+
+ + {{psginfo.title}} + + + {{psginfo.introduction}} + + + + +
+
diff --git a/src/components/ExpListContent.vue b/src/components/ExpListContent.vue index d96ff24..ca6caab 100644 --- a/src/components/ExpListContent.vue +++ b/src/components/ExpListContent.vue @@ -2,7 +2,66 @@ import {defineComponent} from 'vue' export default defineComponent({ - name: "ExpListContent" + name: "ExpListContent", + data(){ + return{ + titles:[], + error:null, + isLoading: false, + pagination: null + } + }, + methods:{ + fetch_items:function(){ + this.isLoading=true; + this.error=null; + const params = new URLSearchParams(window.location.search); + const type = params.get('type'); + console.log('type!',type); + let pageNum=1; + if(this.isActiveRoute('Examples')){ + const params = new URLSearchParams(window.location.search); + const page = params.get('page'); + if(page!=null){ + pageNum=parseInt(page, 10); + } + } + let reqarg='/api/project-examples?fields=title,createdAt&sort=createdAt:desc&pagination[page]='+pageNum+'&pagination[pageSize]=15'; + this.$axios.get(reqarg) + .then(response =>{ + const resp = response.data; + this.pagination= resp.meta.pagination; + // if(resp.meta.pagination.pageCount==0){ + // window.location.href = '/Examples'; + // console.log('turn'); + // } + if (resp && Array.isArray(resp.data)) { + this.titles = resp.data; + console.log('reqarg',reqarg); + if(this.titles.length==0){ + this.error = "返回的 JSON 对象中不存在 'data' 数组"; + } + } else { + this.error = "返回的 JSON 对象中不存在 'data' 数组"; + } + }) + .catch(err => { + console.error(err); + this.error = '请求失败,请稍后重试'; + }) + .finally(() => { + this.isLoading = false; + }); + }, + isActiveRoute(routename) { + // Example: Apply style if route name starts with 'user-' + console.log('Current route name:', this.$route.name, 'Comparing with:', routename); + return this.$route.name === routename; + } + }, + mounted() { + this.fetch_items(); + } }) @@ -14,6 +73,15 @@ export default defineComponent({ + + +
+ + + {{ item.title }} + + +