刘光辉
7 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<script setup lang="ts">
import type { OperationState, RuntimeStatus } from '../stores/annotation';
 
import { computed } from 'vue';
 
const props = withDefaults(
  defineProps<{
    fatalMessage?: string;
    operation: OperationState;
    retryable?: boolean;
    sdkAvailable?: boolean;
    status: RuntimeStatus;
  }>(),
  { fatalMessage: 'ONLYOFFICE SDK 未加载,无法初始化插件', retryable: false, sdkAvailable: true },
);
const emit = defineEmits<{ retry: [] }>();
 
const connectionError = computed(() => props.sdkAvailable && props.status === 'error');
const connectionErrorMessage = computed(() => (props.operation.kind === 'error' && props.operation.message ? props.operation.message : '插件连接失败'));
const connectionStatus = computed<'default' | 'error' | 'processing' | 'success'>(() => {
  if (props.status === 'ready') return 'success';
  if (props.status === 'working') return 'processing';
  if (props.status === 'error') return 'error';
  return 'default';
});
const connectionText = computed(() => {
  if (props.status === 'ready') return '已连接';
  if (props.status === 'working') return '处理中';
  if (props.status === 'error') return '连接异常';
  return '加载中';
});
</script>
 
<template>
  <div class="operation-status">
    <div class="status-line">
      <a-badge class="connection-status" :status="connectionStatus" :text="connectionText" data-test="connection-status" />
      <span class="plugin-version" data-test="plugin-version">v0.1.0</span>
    </div>
 
    <a-result
      v-if="!sdkAvailable || connectionError"
      class="fatal-result"
      status="error"
      :sub-title="sdkAvailable ? connectionErrorMessage : fatalMessage"
      :title="sdkAvailable ? '插件连接失败' : '插件无法启动'">
      <template v-if="sdkAvailable && retryable" #extra>
        <a-button data-test="retry-initialization" type="primary" @click="emit('retry')">重试</a-button>
      </template>
    </a-result>
  </div>
</template>