From 7ae3d6980245d7e8f282fa0cb9ba5816cf8e6538 Mon Sep 17 00:00:00 2001 From: ChenWei Date: Wed, 23 Oct 2024 17:43:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20auth=E5=8A=9F=E8=83=BD=E6=8B=93?= =?UTF-8?q?=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. github release 脚本 2. getOtac & openPage拓展 & auth示例完善 & doc 更新 3. remove sensitive info --- .gitignore | 1 + .vscode/settings.json | 7 +- examples/example-auth-react/src/App.css | 7 + examples/example-auth-react/src/App.tsx | 162 +++++++++++++++++++- examples/example-auth-vue/src/App.vue | 166 ++++++++++++++++++-- examples/example-auth-vue/src/style.css | 8 + examples/example-auth/index.html | 192 ++++++++++++++++++------ examples/example-auth/src/index.js | 140 +++++++++++++---- sh/publish.ts | 7 +- sh/release_new.sh | 84 +++++++++++ xterio-auth/README.md | 108 ++++++++----- xterio-auth/index.html | 188 +++++++++++++++++------ xterio-auth/src/interfaces/loginInfo.ts | 41 +++-- xterio-auth/src/main.ts | 121 ++++++++++++--- xterio-auth/src/modules/AuthService.ts | 15 +- xterio-auth/src/modules/XterAuth.ts | 4 +- xterio-auth/src/modules/XterAuthInfo.ts | 4 +- xterio-auth/src/modules/XterPage.ts | 50 +++--- xterio-auth/src/utils/const.ts | 2 +- 19 files changed, 1068 insertions(+), 239 deletions(-) create mode 100644 sh/release_new.sh diff --git a/.gitignore b/.gitignore index 7d72950..12aaae6 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,4 @@ dist* .turbo +sensitive.txt \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 9fd4461..26daa18 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,8 +12,13 @@ "eslint.format.enable": true, "eslint.codeActionsOnSave.rules": null, "eslint.codeActionsOnSave.mode": "all", - "vs-code-prettier-eslint.prettierLast": true + "vs-code-prettier-eslint.prettierLast": true, // //关闭js/ts默认format,统一用eslint // "javascript.format.enable": false, // "typescript.format.enable": false + // 禁用 VSCode 默认的 HTML 格式化 + "html.format.enable": false, + "[html]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } } \ No newline at end of file diff --git a/examples/example-auth-react/src/App.css b/examples/example-auth-react/src/App.css index b9d355d..c8a2067 100644 --- a/examples/example-auth-react/src/App.css +++ b/examples/example-auth-react/src/App.css @@ -36,6 +36,13 @@ .card { padding: 2em; } +.row{ + display: flex; + flex-direction: row; +} +.justify-center{ + justify-content: center; +} .read-the-docs { color: #888; diff --git a/examples/example-auth-react/src/App.tsx b/examples/example-auth-react/src/App.tsx index 88780bf..ae33309 100644 --- a/examples/example-auth-react/src/App.tsx +++ b/examples/example-auth-react/src/App.tsx @@ -7,12 +7,24 @@ import { IUserInfo, LoginType, OpenPageMode, + PageOptionParam, PageType, XterEventEmiter, XTERIO_EVENTS, XterioAuth } from '@xterio-sdk/auth' +const isChecked = (cls: string) => { + const ele = document.getElementsByClassName(cls)?.[0] + // console.log('ele', ele) + const input = ele?.getElementsByTagName('input')?.[0] + return input?.checked +} +const getRadioValue = (name: string) => { + const tab: HTMLInputElement | null = document.querySelector(`input[name="${name}"]:checked`) + return tab?.value +} + function App() { const [userinfo, setUserinfo] = useState('') //这种形式记录不够准确,比如登录态中途变更时,该页面无法及时获悉。所以对于需要判断登录的操作,直接调用XterioAuth.isLogin即可 @@ -47,7 +59,7 @@ function App() { XterioAuth.logout() } const openPage = async (_t: OpenPageMode) => { - const res = await XterioAuth.openPage(currentPage, _t) + const res = await XterioAuth.openPage(currentPage, _t, getPageParam()) if (_t === OpenPageMode.iframeDom) { console.log('dom=', res) alert(res) @@ -56,6 +68,64 @@ function App() { alert(res) } } + const getPageParam = () => { + let dic: PageOptionParam = {} + const curPage = currentPage + + if (curPage === PageType.asset) { + const value = (getRadioValue('asset_active_tab_option') || 'ingame') as PageOptionParam['active'] + dic = { ...dic, active: value } + } + if (curPage === PageType.setting) { + const value = (getRadioValue('setting_active_tab_option') || 'account') as PageOptionParam['tab'] + dic = { ...dic, tab: value } + } + if (curPage === PageType.nft_collection) { + dic = { ...dic, collection: '65e04d9b65fca97f09ff8f42' } + } + // debugger + + if (isChecked('hide_wallet_entrance')) { + dic = { ...dic, hide_wallet_entrance: true } + } + if (isChecked('hide_account_entrance')) { + dic = { ...dic, hide_account_entrance: true } + } + if (isChecked('hide_menu_entrance')) { + dic = { ...dic, hide_menu_entrance: true } + } + if (isChecked('hide_sign_out')) { + dic = { ...dic, hide_sign_out: true } + } + if (isChecked('hide_footer')) { + dic = { ...dic, hide_footer: true } + } + if (isChecked('disable_logo_click')) { + dic = { ...dic, disable_logo_click: true } + } + if (isChecked('hide_game_select') && curPage === PageType.asset) { + dic = { ...dic, hide_game_select: true } + } + if (isChecked('hide_game_tokens') && curPage === PageType.asset) { + dic = { ...dic, hide_game_tokens: true } + } + if (isChecked('hide_game_filter') && curPage === PageType.nft_market) { + dic = { ...dic, hide_game_filter: true } + } + + console.log('dic=', dic) + return dic + } + const getOtac = async () => { + const _otac = await XterioAuth.getOtac() + console.log('_otac=', _otac) + alert(_otac) + } + const getIdToken = async () => { + const _idToken = await XterioAuth.getIdToken() + console.log('_idToken=', _idToken) + alert(_idToken) + } return ( <> @@ -76,13 +146,97 @@ function App() { + +

当前要打开的页面: {currentPage}

- - - + + + +
+
+

全局控制参数:

+
+
+ + 隐藏钱包入口 +
+
+ + 隐藏账号入口 +
+
+ + 隐藏顶部导航栏(仅H5生效) +
+
+ + 隐藏登出按钮 +
+
+ + 隐藏页脚 +
+
+ + 禁用左上角logo点击跳转首页 +
+
+
+
+

页面独有参数:

+ {currentPage === PageType.asset && ( +
+
定位到对应nft tab :
+
+ + + + +
+
+ )} + {currentPage === PageType.asset && ( +
+ + 隐藏游戏选择(资产页) +
+ )} + {currentPage === PageType.asset && ( +
+ + 隐藏token部分(资产页) +
+ )} + {currentPage === PageType.nft_market && ( +
+ + 隐藏游戏filter(nft市场页) +
+ )} + {currentPage === PageType.setting && ( +
+
定位到对应tab页 :
+
+ + + + + + + + +
+
+ )} + {currentPage === PageType.nft_market && ( +
tip: keyword & features 参考文档
+ )} + {currentPage === PageType.nft_collection && ( +
tip: features 参考文档,collection必传(示例为写死的值)
+ )}

打开页面的方式如下:

diff --git a/examples/example-auth-vue/src/App.vue b/examples/example-auth-vue/src/App.vue index a50d190..819e684 100644 --- a/examples/example-auth-vue/src/App.vue +++ b/examples/example-auth-vue/src/App.vue @@ -1,6 +1,17 @@