diff --git a/src/views/jarvis/docSync/components/WPS365Config.vue b/src/views/jarvis/docSync/components/WPS365Config.vue
index dd756ae..2e2a6c4 100644
--- a/src/views/jarvis/docSync/components/WPS365Config.vue
+++ b/src/views/jarvis/docSync/components/WPS365Config.vue
@@ -33,12 +33,26 @@
刷新状态
-
+
- {{ userInfo.user_id || '-' }}
- {{ userInfo.name || '-' }}
- {{ userInfo.email || '-' }}
+ {{ tokenInfo?.userId || '-' }}
+
+ 有效
+ 已过期
+
+
+ {{ Math.floor(tokenInfo.expiresIn / 60) }} 分钟
+
+
+ 测试API调用
+
@@ -56,7 +70,7 @@
- 在WPS365开放平台注册应用并获取AppID和AppKey
- 配置回调地址:
https://jarvis.van333.cn/wps365-callback
- - 在权限管理中添加
file.read 和 ksheet:read 权限
+ - 在权限管理中添加
kso.file.readwrite 权限(支持在线表格操作)
- 点击"立即授权"完成用户授权
- 授权成功后即可使用API读取和编辑在线表格
@@ -78,7 +92,8 @@
import {
getWPS365AuthUrl,
getWPS365TokenStatus,
- getWPS365UserInfo
+ getWPS365UserInfo,
+ getWPS365FileList
} from '@/api/jarvis/wps365'
export default {
@@ -87,7 +102,8 @@ export default {
return {
isAuthorized: false,
userInfo: null,
- userId: 'default_user' // TODO: 从当前登录用户获取
+ userId: null, // 从token状态中获取
+ tokenInfo: null
}
},
created() {
@@ -102,9 +118,15 @@ export default {
/** 检查授权状态 */
async checkAuthStatus() {
try {
+ // 不传userId,让后端自动查找token
const response = await getWPS365TokenStatus(this.userId)
if (response.code === 200) {
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) {
this.loadUserInfo()
}
@@ -148,13 +170,20 @@ export default {
const messageHandler = (event) => {
if (event.data && event.data.type === 'wps365_oauth_callback') {
window.removeEventListener('message', messageHandler)
- this.checkAuthStatus()
- this.$message.success('授权完成')
+ // 如果回调消息包含userId,更新它
+ if (event.data.userId) {
+ this.userId = event.data.userId
+ }
+ // 延迟一下再刷新,确保后端已保存token
+ setTimeout(() => {
+ this.checkAuthStatus()
+ this.$message.success('授权完成')
+ }, 500)
}
}
window.addEventListener('message', messageHandler)
- // 3秒后刷新配置状态
+ // 3秒后刷新配置状态(作为备用,防止消息监听失败)
setTimeout(() => {
this.checkAuthStatus()
}, 3000)
@@ -168,6 +197,34 @@ export default {
async handleRefreshAuth() {
await this.checkAuthStatus()
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)
+ }
}
}
}