error.vue 4.1 KB

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