2026-03-16 14:21:04 +08:00

265 lines
6.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div>
<!-- 表单部分(生成链接前显示) -->
<div v-if="!authLink">
<el-form ref="formRef" :model="form" :rules="rules" label-width="120px" label-position="right" size="default">
<el-form-item label="真实姓名" prop="employees_name">
<el-input v-model="form.employees_name" placeholder="请输入您的真实姓名" clearable style="width: 100%"
@keyup.enter="handleSubmit" />
<div class="form-tips">请填写您的真实姓名,用于商家管理员审核</div>
</el-form-item>
<el-form-item label="申请缘由" prop="remark">
<el-input v-model="form.remark" placeholder="请输入您的申请缘由" clearable style="width: 100%"
@keyup.enter="handleSubmit" />
<div class="form-tips">请填写您的申请缘由,用于商家管理员审核</div>
</el-form-item>
<el-form-item>
<div style="text-align: right; margin-top: 20px;">
<el-button @click="$emit('cancel')">取消</el-button>
<el-button type="primary" :loading="loading" @click="handleSubmit">
生成授权链接
</el-button>
</div>
</el-form-item>
</el-form>
</div>
<!-- 授权链接显示部分(生成链接后显示) -->
<div v-else class="auth-result-container">
<div class="success-header">
<el-icon class="success-icon" color="#67C23A" size="48"><SuccessFilled /></el-icon>
<h3>授权链接已生成!</h3>
</div>
<div class="result-content">
<p class="result-tips">请将以下授权链接发送给商家管理员进行审批</p>
<div class="link-info">
<div class="info-item">
<span class="info-label">申请人:</span>
<span class="info-value">{{ form.employees_name }}</span>
</div>
<div class="info-item">
<span class="info-label">申请类型:</span>
<el-tag type="primary" size="small">加入商家</el-tag>
</div>
</div>
<div class="link-display">
<div class="link-label">授权链接:</div>
<div class="link-box">
<div class="link-content">{{ authLink }}</div>
<div class="link-actions">
<el-tooltip content="复制链接" placement="top">
<el-button type="success" icon="CopyDocument" @click="copyLink" size="small" circle />
</el-tooltip>
<el-tooltip content="重新生成" placement="top">
<el-button type="warning" icon="Refresh" @click="resetForm" size="small" circle />
</el-tooltip>
</div>
</div>
</div>
<div class="instructions">
<el-alert title="温馨提示" type="info" :closable="false" style="margin-top: 20px;">
<template #default>
<ul class="instructions-list">
<li>此链接有效期24小时,过期需要重新生成</li>
<li>管理员点击链接后可以为您分配职位和权限</li>
<li>审批通过后刷新即可使用系统</li>
<li>请勿将链接分享给无关人员</li>
</ul>
</template>
</el-alert>
</div>
<div class="result-actions">
<el-button @click="$emit('cancel')">返回</el-button>
<el-button type="primary" @click="copyLinkAndClose">
<el-icon><CopyDocument /></el-icon>
复制链接并关闭
</el-button>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive } from 'vue'
import { joinStore } from '@/api/store'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { SuccessFilled, CopyDocument, Refresh } from '@element-plus/icons-vue'
import { useClipboard } from '@vueuse/core'
const { copy } = useClipboard()
const emit = defineEmits(['success', 'cancel'])
const formRef = ref<FormInstance>()
const loading = ref(false)
const authLink = ref('')
const form = reactive({
employees_name: '',
remark: ''
})
const rules = reactive<FormRules>({
employees_name: [
{ required: true, message: '请输入真实姓名', trigger: 'blur' }
],
remark: [
{ required: true, message: '请输入申请缘由', trigger: 'blur' }
]
})
const handleSubmit = async () => {
if (!formRef.value) return
await formRef.value.validate(async (valid) => {
if (valid) {
loading.value = true
try {
const res = await joinStore(form)
authLink.value = res.data // Assuming API returns the link in data
ElMessage.success('生成链接成功')
} catch (error) {
console.error(error)
} finally {
loading.value = false
}
}
})
}
const copyLink = async () => {
try {
await copy(authLink.value)
ElMessage.success('复制成功')
} catch (e) {
ElMessage.error('复制失败')
}
}
const resetForm = () => {
authLink.value = ''
}
const copyLinkAndClose = async () => {
await copyLink()
emit('success')
}
</script>
<style scoped lang="scss">
.form-tips {
font-size: 12px;
color: #909399;
line-height: 1.5;
margin-top: 5px;
}
.auth-result-container {
.success-header {
text-align: center;
margin-bottom: 20px;
.success-icon {
margin-bottom: 10px;
}
h3 {
margin: 0;
color: #303133;
}
}
.result-content {
.result-tips {
text-align: center;
color: #606266;
margin-bottom: 20px;
}
.link-info {
background: #f5f7fa;
padding: 15px;
border-radius: 4px;
margin-bottom: 20px;
.info-item {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
&:last-child {
margin-bottom: 0;
}
.info-label {
color: #909399;
}
.info-value {
color: #303133;
font-weight: 500;
}
}
}
.link-display {
margin-bottom: 20px;
.link-label {
margin-bottom: 8px;
color: #606266;
}
.link-box {
display: flex;
gap: 10px;
.link-content {
flex: 1;
background: #ecf5ff;
border: 1px dashed #409eff;
padding: 8px 12px;
border-radius: 4px;
color: #409eff;
word-break: break-all;
font-size: 13px;
}
.link-actions {
display: flex;
gap: 5px;
}
}
}
.instructions-list {
padding-left: 20px;
margin: 0;
li {
margin-bottom: 5px;
&:last-child {
margin-bottom: 0;
}
}
}
.result-actions {
margin-top: 30px;
text-align: center;
display: flex;
justify-content: center;
gap: 15px;
}
}
}
</style>