Skip to content

Commit

Permalink
feat: example同步更新+发包脚本修改
Browse files Browse the repository at this point in the history
  • Loading branch information
chenweigh committed Sep 18, 2024
1 parent 3c9f86c commit b9e7872
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 13 deletions.
33 changes: 29 additions & 4 deletions examples/example-auth-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'

import { IUserInfo, LoginType, XterEventEmiter, XterioAuth } from '@xterio-sdk/auth'
import { IUserInfo, LoginType, OpenPageMode, PageType, XterEventEmiter, XterioAuth } from '@xterio-sdk/auth'

function App() {
const [userinfo, setUserinfo] = useState('')
const [isLogin, setIsLogin] = useState(XterioAuth.isLogin)
const [currentPage, setCurrentPage] = useState(PageType.asset)

useEffect(() => {
//监听登录成功事件
XterEventEmiter.subscribe((res: IUserInfo) => {
const unsubscribe = XterEventEmiter.subscribe((res: IUserInfo) => {
console.log('info1=', res)
setUserinfo(JSON.stringify(res))
setIsLogin(XterioAuth.isLogin)
})
return () => {
XterEventEmiter.unsubscribe()
unsubscribe?.()
}
}, [])

Expand All @@ -29,6 +30,16 @@ function App() {
setUserinfo('')
setIsLogin(XterioAuth.isLogin)
}
const openPage = async (_t: OpenPageMode) => {
const res = await XterioAuth.openPage(currentPage, _t)
if (_t === OpenPageMode.iframeDom) {
console.log('dom=', res)
alert(res)
} else if (_t === OpenPageMode.iframeUri) {
console.log('uri=', res)
alert(res)
}
}

return (
<>
Expand All @@ -46,9 +57,23 @@ function App() {
<p>用户信息: {userinfo}</p>
<button onClick={() => login()}>默认登录</button>
<button onClick={() => login(LoginType.Email)}>邮箱登录</button>
<button onClick={() => login(LoginType.Mini)}>TT 登录</button>
<button onClick={() => login(LoginType.Mini)}>TG 登录</button>
<button onClick={logout}>退出登录</button>
</div>
<div className="card">
<p>当前要打开的页面: {currentPage}</p>
<button onClick={() => setCurrentPage(PageType.asset)}>资产页</button>
<button onClick={() => setCurrentPage(PageType.account)}>账户页</button>
<button onClick={() => setCurrentPage(PageType.wallet)}>钱包页</button>
<button onClick={() => setCurrentPage(PageType.nft)}>nft页</button>
</div>
<div className="card">
<p>打开页面的方式如下:</p>
<button onClick={() => openPage(OpenPageMode.alert)}>弹框形式(iframe)</button>
<button onClick={() => openPage(OpenPageMode.page)}>新页面形式</button>
<button onClick={() => openPage(OpenPageMode.iframeDom)}>dom形式</button>
<button onClick={() => openPage(OpenPageMode.iframeUri)}>uri形式</button>
</div>
</>
)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/example-auth-react/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const devConfig = {
redirect_uri: 'http://localhost:3000/',
client_id: '4gsmgur6gkp8u9ps8dlco3k7eo',
client_secret: 'ABC23',
app_id: ''
app_id: 'apiautotest'
}
//跳出去跳回来得保证redirect_uri地址一致才行
const stageConfig = {
Expand Down
36 changes: 33 additions & 3 deletions examples/example-auth-vue/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue'
import { IUserInfo, LoginType, XterEventEmiter, XterioAuth } from '@xterio-sdk/auth'
import { IUserInfo, LoginType, OpenPageMode, PageType, XterEventEmiter, XterioAuth } from '@xterio-sdk/auth'
defineProps<{ msg: string }>()
const userinfo = ref('')
const isLogin = ref(XterioAuth.isLogin)
const unsubscribe = ref()
const currentPage = ref(PageType.asset)
onMounted(() => {
XterEventEmiter.subscribe((res: IUserInfo) => {
unsubscribe.value = XterEventEmiter.subscribe((res: IUserInfo) => {
console.log('info1=', res)
userinfo.value = JSON.stringify(res)
isLogin.value = XterioAuth.isLogin
})
})
onUnmounted(() => {
XterEventEmiter.unsubscribe()
unsubscribe.value?.()
})
const login = (mode?: LoginType) => {
Expand All @@ -26,6 +28,16 @@ const logout = () => {
userinfo.value = ''
isLogin.value = XterioAuth.isLogin
}
const openPage = async (_t: OpenPageMode) => {
const res = await XterioAuth.openPage(currentPage.value, _t)
if (_t === OpenPageMode.iframeDom) {
console.log('dom=', res)
alert(res)
} else if (_t === OpenPageMode.iframeUri) {
console.log('uri=', res)
alert(res)
}
}
</script>

<template>
Expand All @@ -46,6 +58,24 @@ const logout = () => {
<button @click="login(LoginType.Mini)">TT 登录</button>
<button @click="logout()">退出登录</button>
</div>
<div className="card">
<p>当前要打开的页面: {{ currentPage }}</p>
<button @click="currentPage = PageType.asset">资产页</button>
<button @click="currentPage = PageType.account">账户页</button>
<button @click="currentPage = PageType.wallet">钱包页</button>
<button @click="currentPage = PageType.nft">nft页</button>
</div>
<div className="card">
<p>打开页面的方式如下:</p>
<button @click="openPage(OpenPageMode.alert)">弹框形式(iframe)</button>
<button @click="openPage(OpenPageMode.page)">新页面形式</button>
<button @click="openPage(OpenPageMode.iframeDom)">
dom形式
</button>
<button @click="openPage(OpenPageMode.iframeUri)">
uri形式
</button>
</div>
</template>

<style scoped>
Expand Down
2 changes: 1 addition & 1 deletion examples/example-auth-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { XterioAuth, Env } from '@xterio-sdk/auth'
const redirect_uri = 'http://localhost:3000/'
const client_id = '4gsmgur6gkp8u9ps8dlco3k7eo'
const client_secret = 'ABC23'
const app_id = ''
const app_id = 'apiautotest'
//4gsmgur6gkp8u9ps8dlco3k7eo, 4gsmgur6gkp8u9ps8dlco3aaaa

//初始化一次即可
Expand Down
23 changes: 20 additions & 3 deletions sh/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,32 @@ const AuthJsonData = readJSONSync(pathAuthJson, { encoding: 'utf-8' })
const WalletJsonData = readJSONSync(pathWalletJson, { encoding: 'utf-8' })

const _flag = process.argv[2]
consola.info('_flag=', chalk.blue(_flag))
const _version = process.argv[3]
consola.info('_flag=', chalk.blue(_flag), _version)

async function init() {
const isExecuteAuth = !_flag || _flag === 'auth'
const isExecuteWallet = !_flag || _flag === 'wallet'
const authVersion = AuthJsonData.version
const walletVersion = WalletJsonData.version
const authVersion = _version || AuthJsonData.version
const walletVersion = _version || WalletJsonData.version

if (isExecuteAuth) {
if (_version) {
AuthJsonData.version = _version
writeJSONSync(pathAuthJson, AuthJsonData, { encoding: 'utf-8', spaces: 2 })
await commitVersionFile('auth', _version)
}
await run('npm publish', pathAuth)
// publish success, commit all change content and push release lock.
await run(`bash release.sh auth ${authVersion}`, pathSh)
}

if (isExecuteWallet) {
if (_version) {
WalletJsonData.version = _version
writeJSONSync(pathWalletJson, WalletJsonData, { encoding: 'utf-8', spaces: 2 })
await commitVersionFile('wallet', _version)
}
//tip: change package.json content
WalletJsonData.dependencies['@xterio-sdk/auth'] = '^' + authVersion
writeJSONSync(pathWalletJson, WalletJsonData, { encoding: 'utf-8', spaces: 2 })
Expand All @@ -31,6 +42,12 @@ async function init() {
await reset()
}
}
const commitVersionFile = async (_f: string, _v: string) => {
const path = _f === 'auth' ? pathAuth : pathWallet
await run(`git push origin main && git push new-origin main`)
await run(`git add package.json && git commit -m "feat: npm pkg(${_f}) publish(${_v})"`, path)
await run(`git push origin main && git push new-origin main`)
}
const reset = () => {
WalletJsonData.dependencies['@xterio-sdk/auth'] = 'workspace:^'
writeJSONSync(pathWalletJson, WalletJsonData, { encoding: 'utf-8', spaces: 2 })
Expand Down
2 changes: 1 addition & 1 deletion sh/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ git init
git add -A
git commit -m "$cmg"

git push -f git@gitlab.itlibecc.com:changying/platform/xteriosdk-web.git main:$branch
git push -f git@github.com:XterioTech/XterioSDK-Web.git main:$branch

rm -rf .git

Expand Down

0 comments on commit b9e7872

Please sign in to comment.