<template>
  <view class="error-page">
    <s-empty
      v-if="errCode === 'NetworkError'"
      icon="/static/internet-empty.png"
      :text="$t('public.networdError')"
      showAction
      :actionText="$t('public.reconnect')"
      @clickAction="onReconnect"
      buttonColor="#ff3000"
    ></s-empty>
    <s-empty
      v-else-if="errCode === 'TemplateError'"
      icon="/static/internet-empty.png"
      :text="$t('public.templateNotExist')"
      showAction
      :actionText="$t('public.reload')"
      @clickAction="onReconnect"
      buttonColor="#ff3000"
    ></s-empty>
    <s-empty
      v-else-if="errCode !== ''"
      icon="/static/internet-empty.png"
      :text="$t('public.loadFailed')"
      showAction
      :actionText="$t('public.reload')"
      @clickAction="onReconnect"
      buttonColor="#ff3000"
    ></s-empty>
  </view>
</template>

<script setup>
  import { onLoad } from '@dcloudio/uni-app';
  import { ref } from 'vue';
  import { ShoproInit } from '@/sheep';

  const errCode = ref('');
  const errMsg = ref('');
  onLoad((options) => {
    errCode.value = options.errCode;
    errMsg.value = options.errMsg;
  });
  // 重新连接
  async function onReconnect() {
    uni.reLaunch({
      url: '/pages/index/index',
    });
    ShoproInit();
  }
</script>

<style lang="scss" scoped>
  .error-page {
    width: 100%;
  }
</style>
