user/info的一些更新

This commit is contained in:
Xu Chang 2025-10-15 16:55:02 +08:00
parent 472f8bf21e
commit 60d8c5d147
26 changed files with 128 additions and 29 deletions

View File

@ -66,12 +66,35 @@ export default OakComponent({
},
],
features: ['token'],
formData: ({ data, features }) => {
formData({ data, features }) {
const [token] = data || [];
if (!token) {
return {};
}
const user = token?.user;
const player = token?.player;
const avatarFile = user?.extraFile$entity && user?.extraFile$entity[0];
const avatar = features.extraFile.getUrl(avatarFile);
// 重新取一遍,不然动态更新这里不会变
const [avatarFile] = this.select('extraFile', {
data: {
id: 1,
tag1: 1,
origin: 1,
bucket: 1,
objectId: 1,
filename: 1,
extra1: 1,
type: 1,
entity: 1,
entityId: 1,
extension: 1,
},
filter: {
entity: 'user',
entityId: user?.id,
tag1: 'avatar',
}
});
const avatar = avatarFile && features.extraFile.getUrl(avatarFile);
const nickname = user && user.nickname;
const isLoggedIn = !!token;
const isPlayingAnother = token && token.userId !== token.playerId;

View File

@ -83,10 +83,10 @@ export default OakComponent({
const genderOption = user?.gender &&
this.state.genderOptions.find((ele) => ele.value === user?.gender);
const isRoot = features.token.isReallyRoot();
// 如果是公众号环境,且登录方式是公众号,可以同步用户信息
// 如果是从微信侧登录,可以同步用户信息
const app = features.application.getApplication();
const token = features.token.getToken();
const canSyncPublic = token?.wechatUser?.applicationId === app.id;
const canSyncWechat = (token?.wechatUser?.applicationId === app.id) && this.features.token.isSelf();
const editable = user && user.$$createAt$$ === 1 || user['#oakLegalActions']?.includes('update');
const executable = this.tryExecute();
const commitBtnProps = {
@ -118,7 +118,7 @@ export default OakComponent({
idStateColor: user?.idState && features.style.getColor('user', 'idState', user.idState),
wechatUser: user?.wechatUser$user?.[0],
isRoot,
canSyncPublic,
canSyncWechat,
editable,
executable,
isCreation: this.isCreation(),
@ -176,6 +176,9 @@ export default OakComponent({
});
}
},
syncWechatInfoMp() {
return this.features.token.syncUserInfoWechatMp();
},
checkIdState() {
if (this.state.idState === 'verified') {
this.setMessage({

View File

@ -16,14 +16,17 @@
.avatar-container {
align-self: center;
display: flex;
flex-direction: row;
flex-direction: column;
align-items: center;
justify-content: center;
height: 380rpx;
.avatar-btn {
padding: 0;
width: auto;
margin-top: 10rpx;
min-width: 68rpx;
height: 40rpx;
font-size: xx-small;
}
}

View File

@ -18,6 +18,14 @@
oakPath="{{oakFullpath}}.extraFile$entity"
entity="user"
/>
<l-button
wx:if="{{canSyncWechat}}"
size="mini"
l-class="avatar-btn"
bind:lintap="syncWechatInfoMp"
>
{{t('syncWeChat')}}
</l-button>
</view>
<l-list
title="昵称"

View File

@ -5,7 +5,8 @@
"manage": "管理",
"bind": "绑定",
"verify": "验证",
"syncWeChat": "同步微信信息",
"syncWeChat": "同步",
"notSelf": "当前不是本人身份登录",
"send": "发送验证码",
"cancel": "取消",
"unbind": "解绑",

View File

@ -15,7 +15,7 @@ type DataProps = {
attrs: Record<string, string>;
id: string;
refreshing: boolean;
canSyncPublic: boolean;
canSyncWechat: boolean;
appId: string;
editAttr: string;
executable: boolean | Error;

View File

@ -7,7 +7,7 @@ import Style from './mobile.module.less';
export default function render(props) {
const { data, methods } = props;
const { t, clean, editMobile, goAuthenticate, refreshWechatPublicUserInfo, editPassword, editNickname, editName, editGender, cancelEdit, update, editBirth, execute, } = methods;
const { oakFullpath, executable, nickname, name, birth, gender, mobile, isCreation, id, canSyncPublic, refreshing, editAttr, genderOptions, oakDirty, nnDirty, birthDirty, nameDirty, genderDirty, userStateColor, userStateStr, idStateColor, idStateStr, idState, editable, changeMobileUrl, changePasswordUrl, authenticateUrl, } = data;
const { oakFullpath, executable, nickname, name, birth, gender, mobile, isCreation, id, canSyncWechat, refreshing, editAttr, genderOptions, oakDirty, nnDirty, birthDirty, nameDirty, genderDirty, userStateColor, userStateStr, idStateColor, idStateStr, idState, editable, changeMobileUrl, changePasswordUrl, authenticateUrl, } = data;
return (<div className={Style.container}>
<div className={Style['avatar_container']}>
<OakAvatar oakAutoUnmount={true} oakPath={oakFullpath + '.extraFile$entity'} entity="user" entityId={id} autoUpload={true}/>
@ -75,7 +75,7 @@ export default function render(props) {
});
}}/>
<div className={Style.btnContainer}>
{!oakDirty && canSyncPublic && editable && <Button className={Style.syncWechat} block onClick={() => refreshWechatPublicUserInfo()}>
{!oakDirty && canSyncWechat && editable && <Button className={Style.syncWechat} block onClick={() => refreshWechatPublicUserInfo()}>
{t('syncWeChat')}
</Button>}
{executable === true && <ExtraFileCommit buttonProps={{

View File

@ -22,16 +22,17 @@
<view
wx:for="{{users}}"
wx:key="index"
class="item"
bind:tap="onItemTapMp"
data-id="{{item.id}}"
>
<l-card
type="avatar"
l-class="item"
image="{{item.avatar}}"
title="{{item.name || item.nickname}}"
describe="{{item.mobile}}"
>
<l-list bind:lintap="onItemTapMp" data-id="{{item.id}}">
<l-list data-id="{{item.id}}">
<view class="relation" slot="left-section">
<block wx:if="{{item.userRelation$user.length > 0}}" wx:for="{{item.userRelation$user}}" wx:for-item="item2" wx:for-index="index2" wx:key="index2">
<l-tag l-class="tag" plain="{{true}}">

View File

@ -404,7 +404,8 @@ const i18ns = [
"manage": "管理",
"bind": "绑定",
"verify": "验证",
"syncWeChat": "同步微信信息",
"syncWeChat": "同步",
"notSelf": "当前不是本人身份登录",
"send": "发送验证码",
"cancel": "取消",
"unbind": "解绑",

View File

@ -39,6 +39,7 @@ export declare class Token<ED extends EntityDict> extends Feature {
* @returns
*/
isReallyRoot(): boolean;
isSelf(): boolean;
sendCaptcha(origin: 'email' | 'mobile', content: string, type: 'login' | 'changePassword' | 'confirm'): Promise<string>;
switchTo(userId: string): Promise<void>;
refreshWechatPublicUserInfo(): Promise<void>;

View File

@ -281,6 +281,10 @@ export class Token extends Feature {
const token = this.getToken(true);
return !!token?.player?.isRoot;
}
isSelf() {
const token = this.getToken();
return token?.playerId === token?.userId;
}
async sendCaptcha(origin, content, type) {
const env = await this.environment.getEnv();
if (origin === 'mobile') {

View File

@ -165,6 +165,7 @@ export const tokenProjection = {
userState: 1,
refId: 1,
},
applicationId: 1,
},
email: {
id: 1,

View File

@ -406,7 +406,8 @@ const i18ns = [
"manage": "管理",
"bind": "绑定",
"verify": "验证",
"syncWeChat": "同步微信信息",
"syncWeChat": "同步",
"notSelf": "当前不是本人身份登录",
"send": "发送验证码",
"cancel": "取消",
"unbind": "解绑",

View File

@ -39,6 +39,7 @@ export declare class Token<ED extends EntityDict> extends Feature {
* @returns
*/
isReallyRoot(): boolean;
isSelf(): boolean;
sendCaptcha(origin: 'email' | 'mobile', content: string, type: 'login' | 'changePassword' | 'confirm'): Promise<string>;
switchTo(userId: string): Promise<void>;
refreshWechatPublicUserInfo(): Promise<void>;

View File

@ -284,6 +284,10 @@ class Token extends Feature_1.Feature {
const token = this.getToken(true);
return !!token?.player?.isRoot;
}
isSelf() {
const token = this.getToken();
return token?.playerId === token?.userId;
}
async sendCaptcha(origin, content, type) {
const env = await this.environment.getEnv();
if (origin === 'mobile') {

View File

@ -168,6 +168,7 @@ exports.tokenProjection = {
userState: 1,
refId: 1,
},
applicationId: 1,
},
email: {
id: 1,

View File

@ -67,12 +67,35 @@ export default OakComponent({
},
],
features: ['token'],
formData: ({ data, features }) => {
formData({ data, features }) {
const [token] = data || [];
if (!token) {
return {};
}
const user = token?.user;
const player = token?.player;
const avatarFile = user?.extraFile$entity && user?.extraFile$entity[0];
const avatar = features.extraFile.getUrl(avatarFile);
// 重新取一遍,不然动态更新这里不会变
const [avatarFile] = this.select('extraFile', {
data: {
id: 1,
tag1: 1,
origin: 1,
bucket: 1,
objectId: 1,
filename: 1,
extra1: 1,
type: 1,
entity: 1,
entityId: 1,
extension: 1,
},
filter: {
entity: 'user',
entityId: user?.id,
tag1: 'avatar',
}
});
const avatar = avatarFile && features.extraFile.getUrl(avatarFile);
const nickname = user && user.nickname;
const isLoggedIn = !!token;

View File

@ -16,14 +16,17 @@
.avatar-container {
align-self: center;
display: flex;
flex-direction: row;
flex-direction: column;
align-items: center;
justify-content: center;
height: 380rpx;
.avatar-btn {
padding: 0;
width: auto;
margin-top: 10rpx;
min-width: 68rpx;
height: 40rpx;
font-size: xx-small;
}
}

View File

@ -90,10 +90,10 @@ export default OakComponent({
const isRoot = features.token.isReallyRoot();
// 如果是公众号环境,且登录方式是公众号,可以同步用户信息
// 如果是从微信侧登录,可以同步用户信息
const app = features.application.getApplication();
const token = features.token.getToken();
const canSyncPublic = token?.wechatUser?.applicationId === app.id
const canSyncWechat = (token?.wechatUser?.applicationId === app.id) && this.features.token.isSelf();
const editable = user && user.$$createAt$$ === 1 || user['#oakLegalActions']?.includes('update');
const executable = this.tryExecute();
const commitBtnProps = {
@ -126,7 +126,7 @@ export default OakComponent({
wechatUser: user?.wechatUser$user?.[0],
isRoot,
canSyncPublic,
canSyncWechat,
editable,
executable,
isCreation: this.isCreation(),
@ -185,6 +185,9 @@ export default OakComponent({
});
}
},
syncWechatInfoMp() {
return this.features.token.syncUserInfoWechatMp();
},
checkIdState() {
if (this.state.idState === 'verified') {
this.setMessage({

View File

@ -18,6 +18,14 @@
oakPath="{{oakFullpath}}.extraFile$entity"
entity="user"
/>
<l-button
wx:if="{{canSyncWechat}}"
size="mini"
l-class="avatar-btn"
bind:lintap="syncWechatInfoMp"
>
{{t('syncWeChat')}}
</l-button>
</view>
<l-list
title="昵称"

View File

@ -5,7 +5,8 @@
"manage": "管理",
"bind": "绑定",
"verify": "验证",
"syncWeChat": "同步微信信息",
"syncWeChat": "同步",
"notSelf": "当前不是本人身份登录",
"send": "发送验证码",
"cancel": "取消",
"unbind": "解绑",

View File

@ -27,7 +27,7 @@ type DataProps = {
attrs: Record<string, string>;
id: string;
refreshing: boolean;
canSyncPublic: boolean;
canSyncWechat: boolean;
appId: string;
editAttr: string;
executable: boolean | Error;
@ -92,7 +92,7 @@ export default function render(
mobile,
isCreation,
id,
canSyncPublic,
canSyncWechat,
refreshing,
editAttr,
genderOptions,
@ -266,7 +266,7 @@ export default function render(
}}
/>
<div className={Style.btnContainer}>
{!oakDirty && canSyncPublic && editable && <Button
{!oakDirty && canSyncWechat && editable && <Button
className={Style.syncWechat}
block
onClick={() => refreshWechatPublicUserInfo()}

View File

@ -24,6 +24,7 @@
wx:key="index"
class="item"
bind:tap="onItemTapMp"
data-id="{{item.id}}"
>
<l-card
type="avatar"

View File

@ -406,7 +406,8 @@ const i18ns: I18n[] = [
"manage": "管理",
"bind": "绑定",
"verify": "验证",
"syncWeChat": "同步微信信息",
"syncWeChat": "同步",
"notSelf": "当前不是本人身份登录",
"send": "发送验证码",
"cancel": "取消",
"unbind": "解绑",

View File

@ -397,6 +397,11 @@ export class Token<ED extends EntityDict> extends Feature {
return !!token?.player?.isRoot;
}
isSelf() {
const token = this.getToken();
return token?.playerId === token?.userId;
}
async sendCaptcha(
origin: 'email' | 'mobile',
content: string,

View File

@ -169,6 +169,7 @@ export const tokenProjection: EntityDict['token']['Projection'] = {
userState: 1,
refId: 1,
},
applicationId: 1,
},
email: {
id: 1,