error.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div class="errorBox">
  3. <img src="http://img.bjzxtw.org.cn/pre/image/jpeg/20250701/1751346180738003.jpg" alt="页面不存在" v-if="errorCode == 404">
  4. <!-- <img src="http://img.bjzxtw.org.cn/pre/image/jpeg/20250701/1751346208700657.jpg" alt="服务器渲染错误" v-if="errorCode == 500"> -->
  5. <!-- <div class="errorText" v-if="errorCode == 404">对不起,您访问的页面不存在</div> -->
  6. <div class="errorText">对不起,当前网站遇到了一些问题..</div>
  7. <div class="errorDetail">{{ errorMsg }}</div>
  8. <!-- <div class="errorText">{{ errorMsg }}</div> -->
  9. <div @click="goHome" class="goHome">返回网站首页</div>
  10. </div>
  11. </template>
  12. <script setup lang="ts">
  13. //1.处理错误 start ---------------------------------------->
  14. //获得错误信息
  15. const error:any = useError();
  16. //console.log('错误信息:', error.value);
  17. //获得错误代码与错误文字
  18. const errorCode = ref<number>(0)
  19. const errorText = ref<string>('')
  20. const route:any = useRoute()
  21. errorCode.value = error.value.statusCode;
  22. errorText.value = error.value.message;
  23. console.log('错误代码:', errorCode.value);
  24. console.log('错误明细:', errorText.value);
  25. console.log('错误来源:',route.query.findPage + ".html")
  26. //展示错误详细
  27. const errorMsg = ref('您要访问的页面已不存在!')
  28. //开始查找错误来源:
  29. if(route.query.findPage == 'index'){
  30. const websiteId = ref<number>(0)
  31. //1.确定网站基本信息存在
  32. try {
  33. const responseStatus = await requestDataPromise('/web/getWebsiteAllinfo', {
  34. method: 'GET',
  35. query: {
  36. 'link_textnum':24,
  37. 'link_imgnum':18,
  38. 'link_footnum':4
  39. },
  40. });
  41. if(responseStatus.code == 200){
  42. websiteId.value = responseStatus.data.website_head.id
  43. }
  44. if(responseStatus.code == 0){
  45. errorMsg.value = "网站基本信息获取失败:" + responseStatus.message
  46. }
  47. } catch (error:any) {
  48. errorMsg.value = "网站基本信息获取失败:" + error
  49. }
  50. //2.确定模板信息存在
  51. if(websiteId.value != 0){
  52. try{
  53. const response = await requestDataPromise('/client/indexData', {
  54. method: 'POST',
  55. body: {
  56. 'website_id':websiteId.value,
  57. 'getpage':'index'
  58. },
  59. });
  60. if(response.code == 0){
  61. errorMsg.value = "模板数据获取失败:" + response.message
  62. }
  63. }catch(error:any){
  64. errorMsg.value = "模板数据获取失败:" + error
  65. }
  66. }
  67. }
  68. //1.处理错误 end ---------------------------------------->
  69. //2.处理跳转 start ---------------------------------------->
  70. const router = useRouter()
  71. const goHome = () => {
  72. router.push('/')
  73. }
  74. //2.处理跳转 end ---------------------------------------->
  75. </script>
  76. <style lang="less" scoped>
  77. .errorBox {
  78. width: 100%;
  79. text-align: center;
  80. padding-top: 150px;
  81. img {
  82. width: 404px;
  83. height: 302px;
  84. margin: 0 auto;
  85. }
  86. .goHome {
  87. width: 120px;
  88. height: 32px;
  89. line-height: 32px;
  90. font-size: 14px;
  91. color: #20242E;
  92. text-align: center;
  93. margin: 0 auto;
  94. background: #fff;
  95. border: 1px solid #D4D6D9;
  96. border-radius: 2px;
  97. cursor: pointer;
  98. }
  99. .errorText {
  100. font-size:16px;
  101. color: #727785;
  102. margin-top: 40px;
  103. margin-bottom: 20px;
  104. }
  105. }
  106. .errorDetail {
  107. font-size:14px;
  108. color: #999;
  109. text-align: center;
  110. margin-bottom: 30px;
  111. }
  112. </style>