181 lines
5.0 KiB
JavaScript
181 lines
5.0 KiB
JavaScript
export default OakComponent({
|
|
entity: 'token',
|
|
isList: true,
|
|
projection: {
|
|
id: 1,
|
|
userId: 1,
|
|
playerId: 1,
|
|
value: 1,
|
|
user: {
|
|
id: 1,
|
|
nickname: 1,
|
|
name: 1,
|
|
birth: 1,
|
|
gender: 1,
|
|
idState: 1,
|
|
userState: 1,
|
|
isRoot: 1,
|
|
extraFile$entity: {
|
|
$entity: '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: {
|
|
tag1: 'avatar',
|
|
},
|
|
indexFrom: 0,
|
|
count: 1,
|
|
},
|
|
user$ref: {
|
|
$entity: 'user',
|
|
data: {
|
|
id: 1,
|
|
mobile$user: {
|
|
$entity: 'mobile',
|
|
data: {
|
|
id: 1,
|
|
mobile: 1,
|
|
},
|
|
},
|
|
}
|
|
},
|
|
},
|
|
player: {
|
|
id: 1,
|
|
isRoot: 1,
|
|
},
|
|
},
|
|
filters: [
|
|
{
|
|
filter() {
|
|
const value = this.features.token.getTokenValue();
|
|
return {
|
|
value,
|
|
};
|
|
},
|
|
},
|
|
],
|
|
features: ['token'],
|
|
formData({ data, features }) {
|
|
const [token] = data || [];
|
|
if (!token) {
|
|
return {};
|
|
}
|
|
const user = token?.user;
|
|
const player = token?.player;
|
|
// 重新取一遍,不然动态更新这里不会变
|
|
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;
|
|
const isRoot = !!player?.isRoot;
|
|
return {
|
|
tokenId: token?.id,
|
|
userId: user?.id,
|
|
avatar,
|
|
nickname,
|
|
isLoggedIn,
|
|
isPlayingAnother,
|
|
isRoot,
|
|
};
|
|
},
|
|
properties: {
|
|
onMyInfoClicked: () => undefined,
|
|
myInfoUrl: '',
|
|
manageUserUrl: '',
|
|
loginUrl: '',
|
|
Body: undefined,
|
|
},
|
|
data: {
|
|
refreshing: false,
|
|
},
|
|
methods: {
|
|
async doLogin() {
|
|
this.setState({
|
|
refreshing: true,
|
|
});
|
|
try {
|
|
switch (process.env.OAK_PLATFORM) {
|
|
case 'wechatMp': {
|
|
await this.features.token.loginWechatMp();
|
|
this.setState({
|
|
refreshing: false,
|
|
});
|
|
break;
|
|
}
|
|
case 'web': {
|
|
const { loginUrl } = this.props;
|
|
if (loginUrl) {
|
|
this.navigateTo({
|
|
url: loginUrl,
|
|
});
|
|
}
|
|
else if (process.env.NODE_ENV === 'development') {
|
|
console.warn('loginUrl unset');
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (err) {
|
|
console.error(err);
|
|
}
|
|
},
|
|
gotoUserManage() {
|
|
const { manageUserUrl } = this.props;
|
|
if (manageUserUrl) {
|
|
this.navigateTo({
|
|
url: manageUserUrl,
|
|
});
|
|
}
|
|
else if (process.env.NODE_ENV === 'development') {
|
|
console.warn('manageUserUrl unset');
|
|
}
|
|
},
|
|
gotoMyInfo() {
|
|
const { myInfoUrl, onMyInfoClicked } = this.props;
|
|
if (myInfoUrl) {
|
|
this.navigateTo({
|
|
url: myInfoUrl,
|
|
});
|
|
}
|
|
else if (onMyInfoClicked) {
|
|
onMyInfoClicked();
|
|
}
|
|
else if (process.env.NODE_ENV === 'development') {
|
|
console.warn('myInfoUrl/onMyInfoClicked unset');
|
|
}
|
|
},
|
|
},
|
|
});
|