34 lines
993 B
Vue
34 lines
993 B
Vue
<template>
|
|
<el-button v-if="enabled" text :loading="busy" @click="launch">进入甄美 ERP ↗</el-button>
|
|
</template>
|
|
<script setup lang="ts">
|
|
import { onMounted, ref } from 'vue'
|
|
import { ElMessage } from 'element-plus'
|
|
import { iamGet, iamPost, identityError } from '@/api/iam-v2'
|
|
const enabled = ref(false),
|
|
busy = ref(false)
|
|
onMounted(async () => {
|
|
try {
|
|
const status = await iamGet('/status')
|
|
enabled.value = !!status.enabled && status.launch_enabled === true
|
|
} catch {
|
|
enabled.value = false
|
|
}
|
|
})
|
|
async function launch() {
|
|
const tab = window.open('about:blank', '_blank')
|
|
if (tab) tab.opener = null
|
|
busy.value = true
|
|
try {
|
|
const r = await iamPost('/launch/start')
|
|
if (tab) tab.location.href = r.url
|
|
else ElMessage.warning('请允许新标签页后再试。')
|
|
} catch (e) {
|
|
tab?.close()
|
|
ElMessage.warning(identityError(e))
|
|
} finally {
|
|
busy.value = false
|
|
}
|
|
}
|
|
</script>
|