2025-04-02 10:48:24 +08:00

46 lines
987 B
JavaScript

import { defineStore } from 'pinia'
import { AppDevSdk } from 'qcloud-iotexplorer-appdev-sdk'
import { getSdkToken } from '@/api/sdk'
export const useSdkStore = defineStore('sdk', {
state() {
return {
sdk: null
}
},
actions: {
async getSdk() {
if (this.sdk.loginManager.isLogin) {
return this.sdk
}
await this.initSdk()
return this.sdk
},
async initSdk() {
try {
const getAccessToken = async () => {
const { code, data, message } = await getSdkToken()
if (code === 0) {
return data
}
uni.showToast({
title: message,
icon: 'none'
})
return null
}
this.sdk = await new AppDevSdk({
appKey: 'mtBfaXFtISXFYVVsd',
getAccessToken
})
this.sdk.init()
} catch (error) {
console.log(111, this.sdk)
console.log('error', error)
}
}
}
})