1
This commit is contained in:
@@ -33,12 +33,26 @@
|
|||||||
刷新状态
|
刷新状态
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="userInfo" class="user-info" style="margin-top: 15px;">
|
<div v-if="isAuthorized" class="token-info" style="margin-top: 15px;">
|
||||||
<el-descriptions :column="2" border size="small">
|
<el-descriptions :column="2" border size="small">
|
||||||
<el-descriptions-item label="用户ID">{{ userInfo.user_id || '-' }}</el-descriptions-item>
|
<el-descriptions-item label="用户ID">{{ tokenInfo?.userId || '-' }}</el-descriptions-item>
|
||||||
<el-descriptions-item label="用户名">{{ userInfo.name || '-' }}</el-descriptions-item>
|
<el-descriptions-item label="Token状态">
|
||||||
<el-descriptions-item label="邮箱">{{ userInfo.email || '-' }}</el-descriptions-item>
|
<el-tag v-if="tokenInfo?.isValid" type="success" size="small">有效</el-tag>
|
||||||
|
<el-tag v-else type="warning" size="small">已过期</el-tag>
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="有效期" v-if="tokenInfo?.expiresIn">
|
||||||
|
{{ Math.floor(tokenInfo.expiresIn / 60) }} 分钟
|
||||||
|
</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
icon="el-icon-video-play"
|
||||||
|
@click="testApi"
|
||||||
|
style="margin-top: 10px;"
|
||||||
|
>
|
||||||
|
测试API调用
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
@@ -56,7 +70,7 @@
|
|||||||
<ol style="margin: 10px 0; padding-left: 20px;">
|
<ol style="margin: 10px 0; padding-left: 20px;">
|
||||||
<li>在WPS365开放平台注册应用并获取AppID和AppKey</li>
|
<li>在WPS365开放平台注册应用并获取AppID和AppKey</li>
|
||||||
<li>配置回调地址:<code>https://jarvis.van333.cn/wps365-callback</code></li>
|
<li>配置回调地址:<code>https://jarvis.van333.cn/wps365-callback</code></li>
|
||||||
<li>在权限管理中添加 <code>file.read</code> 和 <code>ksheet:read</code> 权限</li>
|
<li>在权限管理中添加 <code>kso.file.readwrite</code> 权限(支持在线表格操作)</li>
|
||||||
<li>点击"立即授权"完成用户授权</li>
|
<li>点击"立即授权"完成用户授权</li>
|
||||||
<li>授权成功后即可使用API读取和编辑在线表格</li>
|
<li>授权成功后即可使用API读取和编辑在线表格</li>
|
||||||
</ol>
|
</ol>
|
||||||
@@ -78,7 +92,8 @@
|
|||||||
import {
|
import {
|
||||||
getWPS365AuthUrl,
|
getWPS365AuthUrl,
|
||||||
getWPS365TokenStatus,
|
getWPS365TokenStatus,
|
||||||
getWPS365UserInfo
|
getWPS365UserInfo,
|
||||||
|
getWPS365FileList
|
||||||
} from '@/api/jarvis/wps365'
|
} from '@/api/jarvis/wps365'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -87,7 +102,8 @@ export default {
|
|||||||
return {
|
return {
|
||||||
isAuthorized: false,
|
isAuthorized: false,
|
||||||
userInfo: null,
|
userInfo: null,
|
||||||
userId: 'default_user' // TODO: 从当前登录用户获取
|
userId: null, // 从token状态中获取
|
||||||
|
tokenInfo: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@@ -102,9 +118,15 @@ export default {
|
|||||||
/** 检查授权状态 */
|
/** 检查授权状态 */
|
||||||
async checkAuthStatus() {
|
async checkAuthStatus() {
|
||||||
try {
|
try {
|
||||||
|
// 不传userId,让后端自动查找token
|
||||||
const response = await getWPS365TokenStatus(this.userId)
|
const response = await getWPS365TokenStatus(this.userId)
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
this.isAuthorized = response.data.hasToken && response.data.isValid
|
this.isAuthorized = response.data.hasToken && response.data.isValid
|
||||||
|
this.tokenInfo = response.data
|
||||||
|
// 如果找到了token,更新userId
|
||||||
|
if (response.data.userId) {
|
||||||
|
this.userId = response.data.userId
|
||||||
|
}
|
||||||
if (this.isAuthorized) {
|
if (this.isAuthorized) {
|
||||||
this.loadUserInfo()
|
this.loadUserInfo()
|
||||||
}
|
}
|
||||||
@@ -148,13 +170,20 @@ export default {
|
|||||||
const messageHandler = (event) => {
|
const messageHandler = (event) => {
|
||||||
if (event.data && event.data.type === 'wps365_oauth_callback') {
|
if (event.data && event.data.type === 'wps365_oauth_callback') {
|
||||||
window.removeEventListener('message', messageHandler)
|
window.removeEventListener('message', messageHandler)
|
||||||
|
// 如果回调消息包含userId,更新它
|
||||||
|
if (event.data.userId) {
|
||||||
|
this.userId = event.data.userId
|
||||||
|
}
|
||||||
|
// 延迟一下再刷新,确保后端已保存token
|
||||||
|
setTimeout(() => {
|
||||||
this.checkAuthStatus()
|
this.checkAuthStatus()
|
||||||
this.$message.success('授权完成')
|
this.$message.success('授权完成')
|
||||||
|
}, 500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.addEventListener('message', messageHandler)
|
window.addEventListener('message', messageHandler)
|
||||||
|
|
||||||
// 3秒后刷新配置状态
|
// 3秒后刷新配置状态(作为备用,防止消息监听失败)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.checkAuthStatus()
|
this.checkAuthStatus()
|
||||||
}, 3000)
|
}, 3000)
|
||||||
@@ -168,6 +197,34 @@ export default {
|
|||||||
async handleRefreshAuth() {
|
async handleRefreshAuth() {
|
||||||
await this.checkAuthStatus()
|
await this.checkAuthStatus()
|
||||||
this.$message.success('授权状态已刷新')
|
this.$message.success('授权状态已刷新')
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 测试API调用 */
|
||||||
|
async testApi() {
|
||||||
|
if (!this.isAuthorized || !this.userId) {
|
||||||
|
this.$message.warning('请先完成授权')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$message.info('正在测试API调用...')
|
||||||
|
try {
|
||||||
|
// 测试获取文件列表API
|
||||||
|
const response = await getWPS365FileList({
|
||||||
|
userId: this.userId,
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
if (response.code === 200) {
|
||||||
|
this.$message.success('API调用成功!授权有效。')
|
||||||
|
console.log('API响应:', response.data)
|
||||||
|
} else {
|
||||||
|
this.$message.warning('API调用返回错误: ' + (response.msg || '未知错误'))
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.$message.error('API调用失败: ' + (error.msg || error.message))
|
||||||
|
console.error('API调用错误:', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user