mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-04 13:56:07 +02:00
refactor: app.js (#1291)
* refactor: frontend * Fix avatar gallery sort * Update .NET dependencies * Update npm dependencies electron v37.1.0 * bulkRefreshFriends * fix dark theme * Remove crowdin * Fix config.json dialog not updating * VRCX log file fixes & add Cef log * Remove SharedVariable, fix startup * Revert init theme change * Logging date not working? Fix WinformThemer designer error * Add Cef request hander, no more escaping main page * clean * fix * fix * clean * uh * Apply thememode at startup, fixes random user colours * Split database into files * Instance info remove empty lines * Open external VRC links with VRCX * Electron fixes * fix userdialog style * ohhhh * fix store * fix store * fix: load all group members after kicking a user * fix: world dialog favorite button style * fix: Clear VRCX Cache Timer input value * clean * Fix VR overlay * Fix VR overlay 2 * Fix Discord discord rich presence for RPC worlds * Clean up age verified user tags * Fix playerList being occupied after program reload * no `this` * Fix login stuck loading * writable: false * Hide dialogs on logout * add flush sync option * rm LOGIN event * rm LOGOUT event * remove duplicate event listeners * remove duplicate event listeners * clean * remove duplicate event listeners * clean * fix theme style * fix t * clearable * clean * fix ipcEvent * Small changes * Popcorn Palace support * Remove checkActiveFriends * Clean up * Fix dragEnterCef * Block API requests when not logged in * Clear state on login & logout * Fix worldDialog instances not updating * use <script setup> * Fix avatar change event, CheckGameRunning at startup * Fix image dragging * fix * Remove PWI * fix updateLoop * add webpack-dev-server to dev environment * rm unnecessary chunks * use <script setup> * webpack-dev-server changes * use <script setup> * use <script setup> * Fix UGC text size * Split login event * t * use <script setup> * fix * Update .gitignore and enable checkJs in jsconfig * fix i18n t * use <script setup> * use <script setup> * clean * global types * fix * use checkJs for debugging * Add watchState for login watchers * fix .vue template * type fixes * rm Vue.filter * Cef v138.0.170, VC++ 2022 * Settings fixes * Remove 'USER:CURRENT' * clean up 2FA callbacks * remove userApply * rm i18n import * notification handling to use notification store methods * refactor favorite handling to use favorite store methods and clean up event emissions * refactor moderation handling to use dedicated functions for player moderation events * refactor friend handling to use dedicated functions for friend events * Fix program startup, move lang init * Fix friend state * Fix status change error * Fix user notes diff * fix * rm group event * rm auth event * rm avatar event * clean * clean * getUser * getFriends * getFavoriteWorlds, getFavoriteAvatars * AvatarGalleryUpload btn style & package.json update * Fix friend requests * Apply user * Apply world * Fix note diff * Fix VR overlay * Fixes * Update build scripts * Apply avatar * Apply instance * Apply group * update hidden VRC+ badge * Fix sameInstance "private" * fix 502/504 API errors * fix 502/504 API errors * clean * Fix friend in same instance on orange showing twice in friends list * Add back in broken friend state repair methods * add types --------- Co-authored-by: Natsumi <cmcooper123@hotmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<safe-dialog :visible.sync="isDialogVisible" :title="$t('dialog.avatar_export.header')" width="650px">
|
||||
<safe-dialog :visible.sync="isDialogVisible" :title="t('dialog.avatar_export.header')" width="650px">
|
||||
<el-checkbox-group
|
||||
v-model="exportSelectedOptions"
|
||||
style="margin-bottom: 10px"
|
||||
@@ -26,7 +26,7 @@
|
||||
<el-dropdown-item style="display: block; margin: 10px 0" @click.native="selectAvatarExportGroup(null)">
|
||||
All Favorites
|
||||
</el-dropdown-item>
|
||||
<template v-for="groupAPI in API.favoriteAvatarGroups">
|
||||
<template v-for="groupAPI in favoriteAvatarGroups">
|
||||
<el-dropdown-item
|
||||
:key="groupAPI.name"
|
||||
style="display: block; margin: 10px 0"
|
||||
@@ -79,145 +79,152 @@
|
||||
</safe-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'AvatarExportDialog',
|
||||
inject: ['API'],
|
||||
props: {
|
||||
avatarExportDialogVisible: Boolean,
|
||||
favoriteAvatars: Array,
|
||||
localAvatarFavoriteGroups: Array,
|
||||
localAvatarFavorites: Object,
|
||||
localAvatarFavoritesList: Array
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
avatarExportContent: '',
|
||||
avatarExportFavoriteGroup: null,
|
||||
avatarExportLocalFavoriteGroup: null,
|
||||
exportSelectedOptions: ['ID', 'Name'],
|
||||
exportSelectOptions: [
|
||||
{ label: 'ID', value: 'id' },
|
||||
{ label: 'Name', value: 'name' },
|
||||
{ label: 'Author ID', value: 'authorId' },
|
||||
{ label: 'Author Name', value: 'authorName' },
|
||||
{ label: 'Thumbnail', value: 'thumbnailImageUrl' }
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isDialogVisible: {
|
||||
get() {
|
||||
return this.avatarExportDialogVisible;
|
||||
},
|
||||
set(value) {
|
||||
this.$emit('update:avatar-export-dialog-visible', value);
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
avatarExportDialogVisible(visible) {
|
||||
if (visible) {
|
||||
this.showAvatarExportDialog();
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showAvatarExportDialog() {
|
||||
this.avatarExportFavoriteGroup = null;
|
||||
this.avatarExportLocalFavoriteGroup = null;
|
||||
this.updateAvatarExportDialog();
|
||||
},
|
||||
handleCopyAvatarExportData(event) {
|
||||
if (event.target.tagName === 'TEXTAREA') {
|
||||
event.target.select();
|
||||
}
|
||||
navigator.clipboard
|
||||
.writeText(this.avatarExportContent)
|
||||
.then(() => {
|
||||
this.$message({
|
||||
message: 'Copied successfully!',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Copy failed:', err);
|
||||
this.$message.error('Copy failed!');
|
||||
});
|
||||
},
|
||||
updateAvatarExportDialog() {
|
||||
const formatter = function (str) {
|
||||
if (/[\x00-\x1f,"]/.test(str) === true) {
|
||||
return `"${str.replace(/"/g, '""')}"`;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
const propsForQuery = this.exportSelectOptions
|
||||
.filter((option) => this.exportSelectedOptions.includes(option.label))
|
||||
.map((option) => option.value);
|
||||
<script setup>
|
||||
import { ref, computed, watch, getCurrentInstance } from 'vue';
|
||||
import { useI18n } from 'vue-i18n-bridge';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useAvatarStore, useFavoriteStore } from '../../../stores';
|
||||
|
||||
function resText(ref) {
|
||||
let resArr = [];
|
||||
propsForQuery.forEach((e) => {
|
||||
resArr.push(formatter(ref?.[e]));
|
||||
});
|
||||
return resArr.join(',');
|
||||
}
|
||||
const { t } = useI18n();
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
const lines = [this.exportSelectedOptions.join(',')];
|
||||
const props = defineProps({
|
||||
avatarExportDialogVisible: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
if (this.avatarExportFavoriteGroup) {
|
||||
this.API.favoriteAvatarGroups.forEach((group) => {
|
||||
if (!this.avatarExportFavoriteGroup || this.avatarExportFavoriteGroup === group) {
|
||||
this.favoriteAvatars.forEach((ref) => {
|
||||
if (group.key === ref.groupKey) {
|
||||
lines.push(resText(ref.ref));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (this.avatarExportLocalFavoriteGroup) {
|
||||
const favoriteGroup = this.localAvatarFavorites[this.avatarExportLocalFavoriteGroup];
|
||||
if (!favoriteGroup) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < favoriteGroup.length; ++i) {
|
||||
const ref = favoriteGroup[i];
|
||||
lines.push(resText(ref));
|
||||
}
|
||||
} else {
|
||||
// export all
|
||||
this.favoriteAvatars.forEach((ref) => {
|
||||
lines.push(resText(ref.ref));
|
||||
});
|
||||
for (let i = 0; i < this.localAvatarFavoritesList.length; ++i) {
|
||||
const avatarId = this.localAvatarFavoritesList[i];
|
||||
const ref = this.API.cachedAvatars.get(avatarId);
|
||||
if (typeof ref !== 'undefined') {
|
||||
lines.push(resText(ref));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.avatarExportContent = lines.join('\n');
|
||||
},
|
||||
selectAvatarExportGroup(group) {
|
||||
this.avatarExportFavoriteGroup = group;
|
||||
this.avatarExportLocalFavoriteGroup = null;
|
||||
this.updateAvatarExportDialog();
|
||||
},
|
||||
selectAvatarExportLocalGroup(group) {
|
||||
this.avatarExportLocalFavoriteGroup = group;
|
||||
this.avatarExportFavoriteGroup = null;
|
||||
this.updateAvatarExportDialog();
|
||||
},
|
||||
getLocalAvatarFavoriteGroupLength(group) {
|
||||
const favoriteGroup = this.localAvatarFavorites[group];
|
||||
if (!favoriteGroup) {
|
||||
return 0;
|
||||
}
|
||||
return favoriteGroup.length;
|
||||
const emit = defineEmits(['update:avatarExportDialogVisible']);
|
||||
|
||||
const favoriteStore = useFavoriteStore();
|
||||
const {
|
||||
favoriteAvatars,
|
||||
favoriteAvatarGroups,
|
||||
localAvatarFavorites,
|
||||
localAvatarFavoritesList,
|
||||
localAvatarFavoriteGroups
|
||||
} = storeToRefs(favoriteStore);
|
||||
const { getLocalAvatarFavoriteGroupLength } = favoriteStore;
|
||||
const avatarStore = useAvatarStore();
|
||||
const { cachedAvatars } = storeToRefs(avatarStore);
|
||||
|
||||
const avatarExportContent = ref('');
|
||||
const avatarExportFavoriteGroup = ref(null);
|
||||
const avatarExportLocalFavoriteGroup = ref(null);
|
||||
const exportSelectedOptions = ref(['ID', 'Name']);
|
||||
const exportSelectOptions = ref([
|
||||
{ label: 'ID', value: 'id' },
|
||||
{ label: 'Name', value: 'name' },
|
||||
{ label: 'Author ID', value: 'authorId' },
|
||||
{ label: 'Author Name', value: 'authorName' },
|
||||
{ label: 'Thumbnail', value: 'thumbnailImageUrl' }
|
||||
]);
|
||||
|
||||
const isDialogVisible = computed({
|
||||
get() {
|
||||
return props.avatarExportDialogVisible;
|
||||
},
|
||||
set(value) {
|
||||
emit('update:avatarExportDialogVisible', value);
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.avatarExportDialogVisible,
|
||||
(value) => {
|
||||
if (value) {
|
||||
showAvatarExportDialog();
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
function showAvatarExportDialog() {
|
||||
avatarExportFavoriteGroup.value = null;
|
||||
avatarExportLocalFavoriteGroup.value = null;
|
||||
updateAvatarExportDialog();
|
||||
}
|
||||
function handleCopyAvatarExportData(event) {
|
||||
if (event.target.tagName === 'TEXTAREA') {
|
||||
event.target.select();
|
||||
}
|
||||
navigator.clipboard
|
||||
.writeText(avatarExportContent.value)
|
||||
.then(() => {
|
||||
proxy.$message({
|
||||
message: 'Copied successfully!',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Copy failed:', err);
|
||||
proxy.$message.error('Copy failed!');
|
||||
});
|
||||
}
|
||||
function updateAvatarExportDialog() {
|
||||
const formatter = function (str) {
|
||||
if (/[\x00-\x1f,"]/.test(str) === true) {
|
||||
return `"${str.replace(/"/g, '""')}"`;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
const propsForQuery = exportSelectOptions.value
|
||||
.filter((option) => exportSelectedOptions.value.includes(option.label))
|
||||
.map((option) => option.value);
|
||||
|
||||
function resText(ref) {
|
||||
let resArr = [];
|
||||
propsForQuery.forEach((e) => {
|
||||
resArr.push(formatter(ref?.[e]));
|
||||
});
|
||||
return resArr.join(',');
|
||||
}
|
||||
|
||||
const lines = [exportSelectedOptions.value.join(',')];
|
||||
|
||||
if (avatarExportFavoriteGroup.value) {
|
||||
favoriteAvatarGroups.value.forEach((group) => {
|
||||
if (!avatarExportFavoriteGroup.value || avatarExportFavoriteGroup.value === group) {
|
||||
favoriteAvatars.value.forEach((ref) => {
|
||||
if (group.key === ref.groupKey) {
|
||||
lines.push(resText(ref.ref));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (avatarExportLocalFavoriteGroup.value) {
|
||||
const favoriteGroup = localAvatarFavorites.value[avatarExportLocalFavoriteGroup.value];
|
||||
if (!favoriteGroup) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < favoriteGroup.length; ++i) {
|
||||
const ref = favoriteGroup[i];
|
||||
lines.push(resText(ref));
|
||||
}
|
||||
} else {
|
||||
// export all
|
||||
favoriteAvatars.value.forEach((ref) => {
|
||||
lines.push(resText(ref.ref));
|
||||
});
|
||||
for (let i = 0; i < localAvatarFavoritesList.value.length; ++i) {
|
||||
const avatarId = localAvatarFavoritesList.value[i];
|
||||
const ref = cachedAvatars.value.get(avatarId);
|
||||
if (typeof ref !== 'undefined') {
|
||||
lines.push(resText(ref));
|
||||
}
|
||||
}
|
||||
}
|
||||
avatarExportContent.value = lines.join('\n');
|
||||
}
|
||||
function selectAvatarExportGroup(group) {
|
||||
avatarExportFavoriteGroup.value = group;
|
||||
avatarExportLocalFavoriteGroup.value = null;
|
||||
updateAvatarExportDialog();
|
||||
}
|
||||
function selectAvatarExportLocalGroup(group) {
|
||||
avatarExportLocalFavoriteGroup.value = group;
|
||||
avatarExportFavoriteGroup.value = null;
|
||||
updateAvatarExportDialog();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
<template>
|
||||
<safe-dialog
|
||||
ref="avatarImportDialog"
|
||||
ref="avatarImportDialogRef"
|
||||
:visible.sync="isVisible"
|
||||
:title="$t('dialog.avatar_import.header')"
|
||||
:title="t('dialog.avatar_import.header')"
|
||||
width="650px">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between">
|
||||
<div style="font-size: 12px">{{ $t('dialog.avatar_import.description') }}</div>
|
||||
<div style="font-size: 12px">{{ t('dialog.avatar_import.description') }}</div>
|
||||
<div style="display: flex; align-items: center">
|
||||
<div v-if="avatarImportDialog.progress">
|
||||
{{ $t('dialog.avatar_import.process_progress') }} {{ avatarImportDialog.progress }} /
|
||||
{{ t('dialog.avatar_import.process_progress') }} {{ avatarImportDialog.progress }} /
|
||||
{{ avatarImportDialog.progressTotal }}
|
||||
<i class="el-icon-loading" style="margin: 0 5px"></i>
|
||||
</div>
|
||||
<el-button v-if="avatarImportDialog.loading" size="small" @click="cancelAvatarImport">
|
||||
{{ $t('dialog.avatar_import.cancel') }}
|
||||
{{ t('dialog.avatar_import.cancel') }}
|
||||
</el-button>
|
||||
<el-button v-else size="small" :disabled="!avatarImportDialog.input" @click="processAvatarImportList">
|
||||
{{ $t('dialog.avatar_import.process_list') }}
|
||||
{{ t('dialog.avatar_import.process_list') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -38,12 +38,12 @@
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ $t('dialog.avatar_import.select_group_placeholder') }}
|
||||
{{ t('dialog.avatar_import.select_group_placeholder') }}
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
</el-button>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<template v-for="groupAPI in API.favoriteAvatarGroups">
|
||||
<template v-for="groupAPI in favoriteAvatarGroups">
|
||||
<el-dropdown-item
|
||||
:key="groupAPI.name"
|
||||
style="display: block; margin: 10px 0"
|
||||
@@ -63,7 +63,7 @@
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ $t('dialog.avatar_import.select_group_placeholder') }}
|
||||
{{ t('dialog.avatar_import.select_group_placeholder') }}
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
</el-button>
|
||||
@@ -88,7 +88,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<el-button size="small" @click="clearAvatarImportTable">
|
||||
{{ $t('dialog.avatar_import.clear_table') }}
|
||||
{{ t('dialog.avatar_import.clear_table') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
@@ -100,27 +100,27 @@
|
||||
!avatarImportDialog.avatarImportLocalFavoriteGroup)
|
||||
"
|
||||
@click="importAvatarImportTable">
|
||||
{{ $t('dialog.avatar_import.import') }}
|
||||
{{ t('dialog.avatar_import.import') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<span v-if="avatarImportDialog.importProgress" style="margin: 10px">
|
||||
<i class="el-icon-loading" style="margin-right: 5px"></i>
|
||||
{{ $t('dialog.avatar_import.import_progress') }}
|
||||
{{ t('dialog.avatar_import.import_progress') }}
|
||||
{{ avatarImportDialog.importProgress }}/{{ avatarImportDialog.importProgressTotal }}
|
||||
</span>
|
||||
<br />
|
||||
<template v-if="avatarImportDialog.errors">
|
||||
<el-button size="small" @click="avatarImportDialog.errors = ''">
|
||||
{{ $t('dialog.avatar_import.clear_errors') }}
|
||||
{{ t('dialog.avatar_import.clear_errors') }}
|
||||
</el-button>
|
||||
<h2 style="font-weight: bold; margin: 5px 0">
|
||||
{{ $t('dialog.avatar_import.errors') }}
|
||||
{{ t('dialog.avatar_import.errors') }}
|
||||
</h2>
|
||||
<pre style="white-space: pre-wrap; font-size: 12px" v-text="avatarImportDialog.errors"></pre>
|
||||
</template>
|
||||
<data-tables v-loading="avatarImportDialog.loading" v-bind="avatarImportTable" style="margin-top: 10px">
|
||||
<el-table-column :label="$t('table.import.image')" width="70" prop="thumbnailImageUrl">
|
||||
<el-table-column :label="t('table.import.image')" width="70" prop="thumbnailImageUrl">
|
||||
<template slot-scope="scope">
|
||||
<el-popover placement="right" height="500px" trigger="hover">
|
||||
<img slot="reference" v-lazy="scope.row.thumbnailImageUrl" class="friends-list-avatar" />
|
||||
@@ -132,21 +132,21 @@
|
||||
</el-popover>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.name')" prop="name">
|
||||
<el-table-column :label="t('table.import.name')" prop="name">
|
||||
<template slot-scope="scope">
|
||||
<span class="x-link" @click="showAvatarDialog(scope.row.id)">
|
||||
{{ scope.row.name }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.author')" width="120" prop="authorName">
|
||||
<el-table-column :label="t('table.import.author')" width="120" prop="authorName">
|
||||
<template slot-scope="scope">
|
||||
<span class="x-link" @click="showUserDialog(scope.row.authorId)">
|
||||
{{ scope.row.authorName }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.status')" width="70" prop="releaseStatus">
|
||||
<el-table-column :label="t('table.import.status')" width="70" prop="releaseStatus">
|
||||
<template slot-scope="scope">
|
||||
<span
|
||||
:style="{
|
||||
@@ -161,7 +161,7 @@
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.action')" width="90" align="right">
|
||||
<el-table-column :label="t('table.import.action')" width="90" align="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" icon="el-icon-close" size="mini" @click="deleteItemAvatarImport(scope.row)">
|
||||
</el-button>
|
||||
@@ -171,186 +171,191 @@
|
||||
</safe-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script setup>
|
||||
import { ref, computed, watch, getCurrentInstance } from 'vue';
|
||||
import { useI18n } from 'vue-i18n-bridge';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { avatarRequest, favoriteRequest } from '../../../api';
|
||||
import utils from '../../../classes/utils';
|
||||
import { adjustDialogZ, removeFromArray } from '../../../shared/utils';
|
||||
import { useAvatarStore, useFavoriteStore, useGalleryStore, useUserStore } from '../../../stores';
|
||||
|
||||
export default {
|
||||
name: 'AvatarImportDialog',
|
||||
inject: ['API', 'adjustDialogZ', 'showFullscreenImageDialog', 'showUserDialog', 'showAvatarDialog'],
|
||||
props: {
|
||||
getLocalAvatarFavoriteGroupLength: Function,
|
||||
localAvatarFavoriteGroups: Array,
|
||||
avatarImportDialogInput: String,
|
||||
avatarImportDialogVisible: Boolean
|
||||
const emit = defineEmits(['update:avatarImportDialogInput']);
|
||||
const { t } = useI18n();
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
const { showUserDialog } = useUserStore();
|
||||
const { favoriteAvatarGroups, avatarImportDialogInput, avatarImportDialogVisible, localAvatarFavoriteGroups } =
|
||||
storeToRefs(useFavoriteStore());
|
||||
const { addLocalAvatarFavorite, getLocalAvatarFavoriteGroupLength } = useFavoriteStore();
|
||||
const { showAvatarDialog, applyAvatar } = useAvatarStore();
|
||||
const { showFullscreenImageDialog } = useGalleryStore();
|
||||
|
||||
const avatarImportDialog = ref({
|
||||
loading: false,
|
||||
progress: 0,
|
||||
progressTotal: 0,
|
||||
input: '',
|
||||
avatarIdList: new Set(),
|
||||
errors: '',
|
||||
avatarImportFavoriteGroup: null,
|
||||
avatarImportLocalFavoriteGroup: null,
|
||||
importProgress: 0,
|
||||
importProgressTotal: 0
|
||||
});
|
||||
|
||||
const avatarImportTable = ref({
|
||||
data: [],
|
||||
tableProps: {
|
||||
stripe: true,
|
||||
size: 'mini'
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
avatarImportDialog: {
|
||||
loading: false,
|
||||
progress: 0,
|
||||
progressTotal: 0,
|
||||
input: '',
|
||||
avatarIdList: new Set(),
|
||||
errors: '',
|
||||
avatarImportFavoriteGroup: null,
|
||||
avatarImportLocalFavoriteGroup: null,
|
||||
importProgress: 0,
|
||||
importProgressTotal: 0
|
||||
},
|
||||
avatarImportTable: {
|
||||
data: [],
|
||||
tableProps: {
|
||||
stripe: true,
|
||||
size: 'mini'
|
||||
},
|
||||
layout: 'table'
|
||||
}
|
||||
};
|
||||
layout: 'table'
|
||||
});
|
||||
|
||||
const avatarImportDialogRef = ref(null);
|
||||
|
||||
const isVisible = computed({
|
||||
get() {
|
||||
return avatarImportDialogVisible.value;
|
||||
},
|
||||
computed: {
|
||||
isVisible: {
|
||||
get() {
|
||||
return this.avatarImportDialogVisible;
|
||||
},
|
||||
set(value) {
|
||||
this.$emit('update:avatar-import-dialog-visible', value);
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
avatarImportDialogVisible(value) {
|
||||
if (value) {
|
||||
this.adjustDialogZ(this.$refs.avatarImportDialog.$el);
|
||||
this.clearAvatarImportTable();
|
||||
this.resetAvatarImport();
|
||||
if (this.avatarImportDialogInput) {
|
||||
this.avatarImportDialog.input = this.avatarImportDialogInput;
|
||||
this.processAvatarImportList();
|
||||
this.$emit('update:avatar-import-dialog-input', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async processAvatarImportList() {
|
||||
const D = this.avatarImportDialog;
|
||||
D.loading = true;
|
||||
const regexAvatarId = /avtr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
|
||||
let match = [];
|
||||
const avatarIdList = new Set();
|
||||
while ((match = regexAvatarId.exec(D.input)) !== null) {
|
||||
avatarIdList.add(match[0]);
|
||||
}
|
||||
D.input = '';
|
||||
D.errors = '';
|
||||
D.progress = 0;
|
||||
D.progressTotal = avatarIdList.size;
|
||||
const data = Array.from(avatarIdList);
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
if (!this.isVisible) {
|
||||
this.resetAvatarImport();
|
||||
}
|
||||
if (!D.loading || !this.isVisible) {
|
||||
break;
|
||||
}
|
||||
const avatarId = data[i];
|
||||
if (!D.avatarIdList.has(avatarId)) {
|
||||
try {
|
||||
const args = await avatarRequest.getAvatar({
|
||||
avatarId
|
||||
});
|
||||
this.avatarImportTable.data.push(args.ref);
|
||||
D.avatarIdList.add(avatarId);
|
||||
} catch (err) {
|
||||
D.errors = D.errors.concat(`AvatarId: ${avatarId}\n${err}\n\n`);
|
||||
}
|
||||
}
|
||||
D.progress++;
|
||||
if (D.progress === avatarIdList.size) {
|
||||
D.progress = 0;
|
||||
}
|
||||
}
|
||||
D.loading = false;
|
||||
},
|
||||
set(value) {
|
||||
avatarImportDialogVisible.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
deleteItemAvatarImport(ref) {
|
||||
utils.removeFromArray(this.avatarImportTable.data, ref);
|
||||
this.avatarImportDialog.avatarIdList.delete(ref.id);
|
||||
},
|
||||
|
||||
resetAvatarImport() {
|
||||
this.avatarImportDialog.input = '';
|
||||
this.avatarImportDialog.errors = '';
|
||||
},
|
||||
|
||||
clearAvatarImportTable() {
|
||||
this.avatarImportTable.data = [];
|
||||
this.avatarImportDialog.avatarIdList = new Set();
|
||||
},
|
||||
|
||||
selectAvatarImportGroup(group) {
|
||||
this.avatarImportDialog.avatarImportLocalFavoriteGroup = null;
|
||||
this.avatarImportDialog.avatarImportFavoriteGroup = group;
|
||||
},
|
||||
|
||||
selectAvatarImportLocalGroup(group) {
|
||||
this.avatarImportDialog.avatarImportFavoriteGroup = null;
|
||||
this.avatarImportDialog.avatarImportLocalFavoriteGroup = group;
|
||||
},
|
||||
|
||||
cancelAvatarImport() {
|
||||
this.avatarImportDialog.loading = false;
|
||||
},
|
||||
addFavoriteAvatar(ref, group, message) {
|
||||
return favoriteRequest
|
||||
.addFavorite({
|
||||
type: 'avatar',
|
||||
favoriteId: ref.id,
|
||||
tags: group.name
|
||||
})
|
||||
.then((args) => {
|
||||
if (message) {
|
||||
this.$message({
|
||||
message: 'Avatar added to favorites',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
return args;
|
||||
});
|
||||
},
|
||||
async importAvatarImportTable() {
|
||||
const D = this.avatarImportDialog;
|
||||
if (!D.avatarImportFavoriteGroup && !D.avatarImportLocalFavoriteGroup) {
|
||||
return;
|
||||
}
|
||||
D.loading = true;
|
||||
const data = [...this.avatarImportTable.data].reverse();
|
||||
D.importProgressTotal = data.length;
|
||||
let ref = '';
|
||||
try {
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
if (!D.loading || !this.isVisible) {
|
||||
break;
|
||||
}
|
||||
ref = data[i];
|
||||
if (D.avatarImportFavoriteGroup) {
|
||||
await this.addFavoriteAvatar(ref, D.avatarImportFavoriteGroup, false);
|
||||
} else if (D.avatarImportLocalFavoriteGroup) {
|
||||
this.$emit('addLocalAvatarFavorite', ref.id, D.avatarImportLocalFavoriteGroup);
|
||||
}
|
||||
utils.removeFromArray(this.avatarImportTable.data, ref);
|
||||
D.avatarIdList.delete(ref.id);
|
||||
D.importProgress++;
|
||||
}
|
||||
} catch (err) {
|
||||
D.errors = `Name: ${ref.name}\nAvatarId: ${ref.id}\n${err}\n\n`;
|
||||
} finally {
|
||||
D.importProgress = 0;
|
||||
D.importProgressTotal = 0;
|
||||
D.loading = false;
|
||||
watch(
|
||||
() => avatarImportDialogVisible.value,
|
||||
(value) => {
|
||||
if (value) {
|
||||
adjustDialogZ(avatarImportDialogRef.value.$el);
|
||||
clearAvatarImportTable();
|
||||
resetAvatarImport();
|
||||
if (avatarImportDialogInput.value) {
|
||||
avatarImportDialog.value.input = avatarImportDialogInput.value;
|
||||
processAvatarImportList();
|
||||
emit('update:avatarImportDialogInput', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
async function processAvatarImportList() {
|
||||
const D = avatarImportDialog.value;
|
||||
D.loading = true;
|
||||
const regexAvatarId = /avtr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
|
||||
let match = [];
|
||||
const avatarIdList = new Set();
|
||||
while ((match = regexAvatarId.exec(D.input)) !== null) {
|
||||
avatarIdList.add(match[0]);
|
||||
}
|
||||
D.input = '';
|
||||
D.errors = '';
|
||||
D.progress = 0;
|
||||
D.progressTotal = avatarIdList.size;
|
||||
const data = Array.from(avatarIdList);
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
if (!isVisible.value) {
|
||||
resetAvatarImport();
|
||||
}
|
||||
if (!D.loading || !isVisible.value) {
|
||||
break;
|
||||
}
|
||||
const avatarId = data[i];
|
||||
if (!D.avatarIdList.has(avatarId)) {
|
||||
try {
|
||||
const args = await avatarRequest.getAvatar({
|
||||
avatarId
|
||||
});
|
||||
const ref = applyAvatar(args.json);
|
||||
avatarImportTable.value.data.push(ref);
|
||||
D.avatarIdList.add(avatarId);
|
||||
} catch (err) {
|
||||
D.errors = D.errors.concat(`AvatarId: ${avatarId}\n${err}\n\n`);
|
||||
}
|
||||
}
|
||||
D.progress++;
|
||||
if (D.progress === avatarIdList.size) {
|
||||
D.progress = 0;
|
||||
}
|
||||
}
|
||||
D.loading = false;
|
||||
}
|
||||
|
||||
function deleteItemAvatarImport(ref) {
|
||||
removeFromArray(avatarImportTable.value.data, ref);
|
||||
avatarImportDialog.value.avatarIdList.delete(ref.id);
|
||||
}
|
||||
|
||||
function resetAvatarImport() {
|
||||
avatarImportDialog.value.input = '';
|
||||
avatarImportDialog.value.errors = '';
|
||||
}
|
||||
|
||||
function clearAvatarImportTable() {
|
||||
avatarImportTable.value.data = [];
|
||||
avatarImportDialog.value.avatarIdList = new Set();
|
||||
}
|
||||
|
||||
function selectAvatarImportGroup(group) {
|
||||
avatarImportDialog.value.avatarImportLocalFavoriteGroup = null;
|
||||
avatarImportDialog.value.avatarImportFavoriteGroup = group;
|
||||
}
|
||||
|
||||
function selectAvatarImportLocalGroup(group) {
|
||||
avatarImportDialog.value.avatarImportFavoriteGroup = null;
|
||||
avatarImportDialog.value.avatarImportLocalFavoriteGroup = group;
|
||||
}
|
||||
|
||||
function cancelAvatarImport() {
|
||||
avatarImportDialog.value.loading = false;
|
||||
}
|
||||
function addFavoriteAvatar(ref, group, message) {
|
||||
return favoriteRequest
|
||||
.addFavorite({
|
||||
type: 'avatar',
|
||||
favoriteId: ref.id,
|
||||
tags: group.name
|
||||
})
|
||||
.then((args) => {
|
||||
if (message) {
|
||||
proxy.$message({
|
||||
message: 'Avatar added to favorites',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
return args;
|
||||
});
|
||||
}
|
||||
async function importAvatarImportTable() {
|
||||
const D = avatarImportDialog.value;
|
||||
if (!D.avatarImportFavoriteGroup && !D.avatarImportLocalFavoriteGroup) {
|
||||
return;
|
||||
}
|
||||
D.loading = true;
|
||||
const data = [...avatarImportTable.value.data].reverse();
|
||||
D.importProgressTotal = data.length;
|
||||
let ref = '';
|
||||
try {
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
if (!D.loading || !isVisible.value) {
|
||||
break;
|
||||
}
|
||||
ref = data[i];
|
||||
if (D.avatarImportFavoriteGroup) {
|
||||
await addFavoriteAvatar(ref, D.avatarImportFavoriteGroup, false);
|
||||
} else if (D.avatarImportLocalFavoriteGroup) {
|
||||
addLocalAvatarFavorite(ref.id, D.avatarImportLocalFavoriteGroup);
|
||||
}
|
||||
removeFromArray(avatarImportTable.value.data, ref);
|
||||
D.avatarIdList.delete(ref.id);
|
||||
D.importProgress++;
|
||||
}
|
||||
} catch (err) {
|
||||
D.errors = `Name: ${ref.name}\nAvatarId: ${ref.id}\n${err}\n\n`;
|
||||
} finally {
|
||||
D.importProgress = 0;
|
||||
D.importProgressTotal = 0;
|
||||
D.loading = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<safe-dialog
|
||||
:visible.sync="isDialogVisible"
|
||||
class="x-dialog"
|
||||
:title="$t('dialog.friend_export.header')"
|
||||
:title="t('dialog.friend_export.header')"
|
||||
width="650px"
|
||||
destroy-on-close>
|
||||
<el-dropdown trigger="click" size="small" @click.native.stop>
|
||||
@@ -19,7 +19,7 @@
|
||||
<el-dropdown-item style="display: block; margin: 10px 0" @click.native="selectFriendExportGroup(null)">
|
||||
All Favorites
|
||||
</el-dropdown-item>
|
||||
<template v-for="groupAPI in API.favoriteFriendGroups">
|
||||
<template v-for="groupAPI in favoriteFriendGroups">
|
||||
<el-dropdown-item
|
||||
:key="groupAPI.name"
|
||||
style="display: block; margin: 10px 0"
|
||||
@@ -42,86 +42,94 @@
|
||||
</safe-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'FriendExportDialog',
|
||||
inject: ['API'],
|
||||
props: {
|
||||
friendExportDialogVisible: Boolean,
|
||||
favoriteFriends: Array
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
friendExportFavoriteGroup: null,
|
||||
friendExportContent: ''
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isDialogVisible: {
|
||||
get() {
|
||||
return this.friendExportDialogVisible;
|
||||
},
|
||||
set(value) {
|
||||
this.$emit('update:friend-export-dialog-visible', value);
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
friendExportDialogVisible(value) {
|
||||
if (value) {
|
||||
this.showFriendExportDialog();
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showFriendExportDialog() {
|
||||
this.friendExportFavoriteGroup = null;
|
||||
this.updateFriendExportDialog();
|
||||
},
|
||||
<script setup>
|
||||
import { ref, computed, watch, getCurrentInstance } from 'vue';
|
||||
import { useI18n } from 'vue-i18n-bridge';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useFavoriteStore } from '../../../stores';
|
||||
|
||||
handleCopyFriendExportData(event) {
|
||||
if (event.target.tagName === 'TEXTAREA') {
|
||||
event.target.select();
|
||||
}
|
||||
navigator.clipboard
|
||||
.writeText(this.friendExportContent)
|
||||
.then(() => {
|
||||
this.$message({
|
||||
message: 'Copied successfully!',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Copy failed:', err);
|
||||
this.$message.error('Copy failed!');
|
||||
});
|
||||
},
|
||||
const { t } = useI18n();
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
updateFriendExportDialog() {
|
||||
const _ = function (str) {
|
||||
if (/[\x00-\x1f,"]/.test(str) === true) {
|
||||
return `"${str.replace(/"/g, '""')}"`;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
const lines = ['UserID,Name'];
|
||||
this.API.favoriteFriendGroups.forEach((group) => {
|
||||
if (!this.friendExportFavoriteGroup || this.friendExportFavoriteGroup === group) {
|
||||
this.favoriteFriends.forEach((ref) => {
|
||||
if (group.key === ref.groupKey) {
|
||||
lines.push(`${_(ref.id)},${_(ref.name)}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
this.friendExportContent = lines.join('\n');
|
||||
},
|
||||
const props = defineProps({
|
||||
friendExportDialogVisible: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
selectFriendExportGroup(group) {
|
||||
this.friendExportFavoriteGroup = group;
|
||||
this.updateFriendExportDialog();
|
||||
const emit = defineEmits(['update:friendExportDialogVisible']);
|
||||
|
||||
const favoriteStore = useFavoriteStore();
|
||||
const { favoriteFriends, favoriteFriendGroups } = storeToRefs(favoriteStore);
|
||||
|
||||
const friendExportFavoriteGroup = ref(null);
|
||||
const friendExportContent = ref('');
|
||||
|
||||
const isDialogVisible = computed({
|
||||
get() {
|
||||
return props.friendExportDialogVisible;
|
||||
},
|
||||
set(value) {
|
||||
emit('update:friendExportDialogVisible', value);
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.friendExportDialogVisible,
|
||||
(value) => {
|
||||
if (value) {
|
||||
showFriendExportDialog();
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
function showFriendExportDialog() {
|
||||
friendExportFavoriteGroup.value = null;
|
||||
updateFriendExportDialog();
|
||||
}
|
||||
|
||||
function handleCopyFriendExportData(event) {
|
||||
if (event.target.tagName === 'TEXTAREA') {
|
||||
event.target.select();
|
||||
}
|
||||
navigator.clipboard
|
||||
.writeText(friendExportContent.value)
|
||||
.then(() => {
|
||||
proxy.$message({
|
||||
message: 'Copied successfully!',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Copy failed:', err);
|
||||
proxy.$message.error('Copy failed!');
|
||||
});
|
||||
}
|
||||
|
||||
function updateFriendExportDialog() {
|
||||
const _ = function (str) {
|
||||
if (/[\x00-\x1f,"]/.test(str) === true) {
|
||||
return `"${str.replace(/"/g, '""')}"`;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
const lines = ['UserID,Name'];
|
||||
favoriteFriendGroups.value.forEach((group) => {
|
||||
if (!friendExportFavoriteGroup.value || friendExportFavoriteGroup.value === group) {
|
||||
favoriteFriends.value.forEach((ref) => {
|
||||
if (group.key === ref.groupKey) {
|
||||
lines.push(`${_(ref.id)},${_(ref.name)}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
friendExportContent.value = lines.join('\n');
|
||||
}
|
||||
|
||||
function selectFriendExportGroup(group) {
|
||||
friendExportFavoriteGroup.value = group;
|
||||
updateFriendExportDialog();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
<template>
|
||||
<safe-dialog
|
||||
ref="friendImportDialog"
|
||||
ref="friendImportDialogRef"
|
||||
:visible.sync="isVisible"
|
||||
:title="$t('dialog.friend_import.header')"
|
||||
:title="t('dialog.friend_import.header')"
|
||||
width="650px">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between">
|
||||
<div style="font-size: 12px">{{ $t('dialog.friend_import.description') }}</div>
|
||||
<div style="font-size: 12px">{{ t('dialog.friend_import.description') }}</div>
|
||||
<div style="display: flex; align-items: center">
|
||||
<div v-if="friendImportDialog.progress">
|
||||
{{ $t('dialog.friend_import.process_progress') }} {{ friendImportDialog.progress }} /
|
||||
{{ t('dialog.friend_import.process_progress') }} {{ friendImportDialog.progress }} /
|
||||
{{ friendImportDialog.progressTotal }}
|
||||
<i class="el-icon-loading" style="margin: 0 5px"></i>
|
||||
</div>
|
||||
<el-button v-if="friendImportDialog.loading" size="small" @click="cancelFriendImport">
|
||||
{{ $t('dialog.friend_import.cancel') }}
|
||||
{{ t('dialog.friend_import.cancel') }}
|
||||
</el-button>
|
||||
<el-button v-else size="small" :disabled="!friendImportDialog.input" @click="processFriendImportList">
|
||||
{{ $t('dialog.friend_import.process_list') }}
|
||||
{{ t('dialog.friend_import.process_list') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -38,12 +38,12 @@
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
<span v-else
|
||||
>{{ $t('dialog.friend_import.select_group_placeholder') }}
|
||||
>{{ t('dialog.friend_import.select_group_placeholder') }}
|
||||
<i class="el-icon-arrow-down el-icon--right"></i
|
||||
></span>
|
||||
</el-button>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<template v-for="groupAPI in API.favoriteFriendGroups">
|
||||
<template v-for="groupAPI in favoriteFriendGroups">
|
||||
<el-dropdown-item
|
||||
:key="groupAPI.name"
|
||||
style="display: block; margin: 10px 0"
|
||||
@@ -64,7 +64,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<el-button size="small" :disabled="friendImportTable.data.length === 0" @click="clearFriendImportTable">
|
||||
{{ $t('dialog.friend_import.clear_table') }}
|
||||
{{ t('dialog.friend_import.clear_table') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
@@ -72,26 +72,26 @@
|
||||
style="margin: 5px"
|
||||
:disabled="friendImportTable.data.length === 0 || !friendImportDialog.friendImportFavoriteGroup"
|
||||
@click="importFriendImportTable">
|
||||
{{ $t('dialog.friend_import.import') }}
|
||||
{{ t('dialog.friend_import.import') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<span v-if="friendImportDialog.importProgress" style="margin: 10px">
|
||||
<i class="el-icon-loading" style="margin-right: 5px"></i>
|
||||
{{ $t('dialog.friend_import.import_progress') }} {{ friendImportDialog.importProgress }}/{{
|
||||
{{ t('dialog.friend_import.import_progress') }} {{ friendImportDialog.importProgress }}/{{
|
||||
friendImportDialog.importProgressTotal
|
||||
}}
|
||||
</span>
|
||||
<br />
|
||||
<template v-if="friendImportDialog.errors">
|
||||
<el-button size="small" @click="friendImportDialog.errors = ''">
|
||||
{{ $t('dialog.friend_import.clear_errors') }}
|
||||
{{ t('dialog.friend_import.clear_errors') }}
|
||||
</el-button>
|
||||
<h2 style="font-weight: bold; margin: 5px 0">{{ $t('dialog.friend_import.errors') }}</h2>
|
||||
<h2 style="font-weight: bold; margin: 5px 0">{{ t('dialog.friend_import.errors') }}</h2>
|
||||
<pre style="white-space: pre-wrap; font-size: 12px" v-text="friendImportDialog.errors"></pre>
|
||||
</template>
|
||||
<data-tables v-loading="friendImportDialog.loading" v-bind="friendImportTable" style="margin-top: 10px">
|
||||
<el-table-column :label="$t('table.import.image')" width="70" prop="currentAvatarThumbnailImageUrl">
|
||||
<el-table-column :label="t('table.import.image')" width="70" prop="currentAvatarThumbnailImageUrl">
|
||||
<template slot-scope="scope">
|
||||
<el-popover placement="right" height="500px" trigger="hover">
|
||||
<template slot="reference">
|
||||
@@ -105,14 +105,14 @@
|
||||
</el-popover>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.name')" prop="displayName">
|
||||
<el-table-column :label="t('table.import.name')" prop="displayName">
|
||||
<template slot-scope="scope">
|
||||
<span class="x-link" :title="scope.row.displayName" @click="showUserDialog(scope.row.id)">
|
||||
{{ scope.row.displayName }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.action')" width="90" align="right">
|
||||
<el-table-column :label="t('table.import.action')" width="90" align="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" icon="el-icon-close" size="mini" @click="deleteItemFriendImport(scope.row)">
|
||||
</el-button>
|
||||
@@ -122,175 +122,174 @@
|
||||
</safe-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import utils from '../../../classes/utils';
|
||||
<script setup>
|
||||
import { ref, computed, watch, getCurrentInstance } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useI18n } from 'vue-i18n-bridge';
|
||||
import { favoriteRequest, userRequest } from '../../../api';
|
||||
import { adjustDialogZ, removeFromArray, userImage, userImageFull } from '../../../shared/utils';
|
||||
import { useFavoriteStore, useGalleryStore, useUserStore } from '../../../stores';
|
||||
|
||||
export default {
|
||||
name: 'FriendImportDialog',
|
||||
inject: ['API', 'userImage', 'userImageFull', 'showFullscreenImageDialog', 'showUserDialog', 'adjustDialogZ'],
|
||||
props: {
|
||||
friendImportDialogVisible: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
},
|
||||
friendImportDialogInput: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: ''
|
||||
}
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const emit = defineEmits(['update:friendImportDialogInput']);
|
||||
|
||||
const { showUserDialog } = useUserStore();
|
||||
const { favoriteFriendGroups, friendImportDialogInput, friendImportDialogVisible } =
|
||||
storeToRefs(useFavoriteStore());
|
||||
const { showFullscreenImageDialog } = useGalleryStore();
|
||||
|
||||
const friendImportDialog = ref({
|
||||
loading: false,
|
||||
progress: 0,
|
||||
progressTotal: 0,
|
||||
input: '',
|
||||
userIdList: new Set(),
|
||||
errors: '',
|
||||
friendImportFavoriteGroup: null,
|
||||
importProgress: 0,
|
||||
importProgressTotal: 0
|
||||
});
|
||||
|
||||
const friendImportTable = ref({
|
||||
data: [],
|
||||
tableProps: {
|
||||
stripe: true,
|
||||
size: 'mini'
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
friendImportDialog: {
|
||||
loading: false,
|
||||
progress: 0,
|
||||
progressTotal: 0,
|
||||
input: '',
|
||||
userIdList: new Set(),
|
||||
errors: '',
|
||||
friendImportFavoriteGroup: null,
|
||||
importProgress: 0,
|
||||
importProgressTotal: 0
|
||||
},
|
||||
friendImportTable: {
|
||||
data: [],
|
||||
tableProps: {
|
||||
stripe: true,
|
||||
size: 'mini'
|
||||
},
|
||||
layout: 'table'
|
||||
}
|
||||
};
|
||||
layout: 'table'
|
||||
});
|
||||
|
||||
const friendImportDialogRef = ref(null);
|
||||
|
||||
const isVisible = computed({
|
||||
get() {
|
||||
return friendImportDialogVisible.value;
|
||||
},
|
||||
computed: {
|
||||
isVisible: {
|
||||
get() {
|
||||
return this.friendImportDialogVisible;
|
||||
},
|
||||
set(value) {
|
||||
this.$emit('update:friend-import-dialog-visible', value);
|
||||
set(value) {
|
||||
friendImportDialogVisible.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
() => friendImportDialogVisible.value,
|
||||
(value) => {
|
||||
if (value) {
|
||||
adjustDialogZ(friendImportDialogRef.value.$el);
|
||||
clearFriendImportTable();
|
||||
resetFriendImport();
|
||||
if (friendImportDialogInput.value) {
|
||||
friendImportDialog.value.input = friendImportDialogInput.value;
|
||||
processFriendImportList();
|
||||
emit('update:friendImportDialogInput', '');
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
friendImportDialogVisible(value) {
|
||||
if (value) {
|
||||
this.adjustDialogZ(this.$refs.friendImportDialog.$el);
|
||||
this.clearFriendImportTable();
|
||||
this.resetFriendImport();
|
||||
if (this.friendImportDialogInput) {
|
||||
this.friendImportDialog.input = this.friendImportDialogInput;
|
||||
this.processFriendImportList();
|
||||
this.$emit('update:friend-import-dialog-input', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
cancelFriendImport() {
|
||||
this.friendImportDialog.loading = false;
|
||||
},
|
||||
deleteItemFriendImport(ref) {
|
||||
utils.removeFromArray(this.friendImportTable.data, ref);
|
||||
this.friendImportDialog.userIdList.delete(ref.id);
|
||||
},
|
||||
clearFriendImportTable() {
|
||||
this.friendImportTable.data = [];
|
||||
this.friendImportDialog.userIdList = new Set();
|
||||
},
|
||||
selectFriendImportGroup(group) {
|
||||
this.friendImportDialog.friendImportFavoriteGroup = group;
|
||||
},
|
||||
async importFriendImportTable() {
|
||||
const D = this.friendImportDialog;
|
||||
D.loading = true;
|
||||
if (!D.friendImportFavoriteGroup) {
|
||||
return;
|
||||
}
|
||||
const data = [...this.friendImportTable.data].reverse();
|
||||
D.importProgressTotal = data.length;
|
||||
let ref = '';
|
||||
try {
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
if (!D.loading || !this.isVisible) {
|
||||
break;
|
||||
}
|
||||
ref = data[i];
|
||||
await this.addFavoriteUser(ref, D.friendImportFavoriteGroup, false);
|
||||
utils.removeFromArray(this.friendImportTable.data, ref);
|
||||
D.userIdList.delete(ref.id);
|
||||
D.importProgress++;
|
||||
}
|
||||
} catch (err) {
|
||||
D.errors = `Name: ${ref.displayName}\nUserId: ${ref.id}\n${err}\n\n`;
|
||||
} finally {
|
||||
D.importProgress = 0;
|
||||
D.importProgressTotal = 0;
|
||||
D.loading = false;
|
||||
}
|
||||
},
|
||||
addFavoriteUser(ref, group, message) {
|
||||
return favoriteRequest
|
||||
.addFavorite({
|
||||
type: 'friend',
|
||||
favoriteId: ref.id,
|
||||
tags: group.name
|
||||
})
|
||||
.then((args) => {
|
||||
if (message) {
|
||||
this.$message({
|
||||
message: 'Friend added to favorites',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
return args;
|
||||
});
|
||||
},
|
||||
async processFriendImportList() {
|
||||
const D = this.friendImportDialog;
|
||||
D.loading = true;
|
||||
const regexFriendId = /usr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
|
||||
let match = [];
|
||||
const userIdList = new Set();
|
||||
while ((match = regexFriendId.exec(D.input)) !== null) {
|
||||
userIdList.add(match[0]);
|
||||
}
|
||||
D.input = '';
|
||||
D.errors = '';
|
||||
D.progress = 0;
|
||||
D.progressTotal = userIdList.size;
|
||||
const data = Array.from(userIdList);
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
if (!this.isVisible) {
|
||||
this.resetFriendImport();
|
||||
}
|
||||
if (!D.loading || !this.isVisible) {
|
||||
break;
|
||||
}
|
||||
const userId = data[i];
|
||||
if (!D.userIdList.has(userId)) {
|
||||
try {
|
||||
const args = await userRequest.getUser({
|
||||
userId
|
||||
});
|
||||
this.friendImportTable.data.push(args.ref);
|
||||
D.userIdList.add(userId);
|
||||
} catch (err) {
|
||||
D.errors = D.errors.concat(`UserId: ${userId}\n${err}\n\n`);
|
||||
}
|
||||
}
|
||||
D.progress++;
|
||||
if (D.progress === userIdList.size) {
|
||||
D.progress = 0;
|
||||
}
|
||||
}
|
||||
D.loading = false;
|
||||
},
|
||||
resetFriendImport() {
|
||||
this.friendImportDialog.input = '';
|
||||
this.friendImportDialog.errors = '';
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
function cancelFriendImport() {
|
||||
friendImportDialog.value.loading = false;
|
||||
}
|
||||
function deleteItemFriendImport(ref) {
|
||||
removeFromArray(friendImportTable.value.data, ref);
|
||||
friendImportDialog.value.userIdList.delete(ref.id);
|
||||
}
|
||||
function clearFriendImportTable() {
|
||||
friendImportTable.value.data = [];
|
||||
friendImportDialog.value.userIdList = new Set();
|
||||
}
|
||||
function selectFriendImportGroup(group) {
|
||||
friendImportDialog.value.friendImportFavoriteGroup = group;
|
||||
}
|
||||
async function importFriendImportTable() {
|
||||
const D = friendImportDialog.value;
|
||||
D.loading = true;
|
||||
if (!D.friendImportFavoriteGroup) {
|
||||
return;
|
||||
}
|
||||
const data = [...friendImportTable.value.data].reverse();
|
||||
D.importProgressTotal = data.length;
|
||||
let ref = '';
|
||||
try {
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
if (!D.loading || !isVisible.value) {
|
||||
break;
|
||||
}
|
||||
ref = data[i];
|
||||
await addFavoriteUser(ref, D.friendImportFavoriteGroup, false);
|
||||
removeFromArray(friendImportTable.value.data, ref);
|
||||
D.userIdList.delete(ref.id);
|
||||
D.importProgress++;
|
||||
}
|
||||
} catch (err) {
|
||||
D.errors = `Name: ${ref.displayName}\nUserId: ${ref.id}\n${err}\n\n`;
|
||||
} finally {
|
||||
D.importProgress = 0;
|
||||
D.importProgressTotal = 0;
|
||||
D.loading = false;
|
||||
}
|
||||
}
|
||||
function addFavoriteUser(ref, group, message) {
|
||||
return favoriteRequest
|
||||
.addFavorite({
|
||||
type: 'friend',
|
||||
favoriteId: ref.id,
|
||||
tags: group.name
|
||||
})
|
||||
.then((args) => {
|
||||
if (message) {
|
||||
proxy.$message({
|
||||
message: 'Friend added to favorites',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
return args;
|
||||
});
|
||||
}
|
||||
async function processFriendImportList() {
|
||||
const D = friendImportDialog.value;
|
||||
D.loading = true;
|
||||
const regexFriendId = /usr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
|
||||
let match = [];
|
||||
const userIdList = new Set();
|
||||
while ((match = regexFriendId.exec(D.input)) !== null) {
|
||||
userIdList.add(match[0]);
|
||||
}
|
||||
D.input = '';
|
||||
D.errors = '';
|
||||
D.progress = 0;
|
||||
D.progressTotal = userIdList.size;
|
||||
const data = Array.from(userIdList);
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
if (!isVisible.value) {
|
||||
resetFriendImport();
|
||||
}
|
||||
if (!D.loading || !isVisible.value) {
|
||||
break;
|
||||
}
|
||||
const userId = data[i];
|
||||
if (!D.userIdList.has(userId)) {
|
||||
try {
|
||||
const args = await userRequest.getUser({
|
||||
userId
|
||||
});
|
||||
friendImportTable.value.data.push(args.ref);
|
||||
D.userIdList.add(userId);
|
||||
} catch (err) {
|
||||
D.errors = D.errors.concat(`UserId: ${userId}\n${err}\n\n`);
|
||||
}
|
||||
}
|
||||
D.progress++;
|
||||
if (D.progress === userIdList.size) {
|
||||
D.progress = 0;
|
||||
}
|
||||
}
|
||||
D.loading = false;
|
||||
}
|
||||
function resetFriendImport() {
|
||||
friendImportDialog.value.input = '';
|
||||
friendImportDialog.value.errors = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<safe-dialog :visible.sync="isDialogVisible" :title="$t('dialog.world_export.header')" width="650px">
|
||||
<safe-dialog :visible.sync="isDialogVisible" :title="t('dialog.world_export.header')" width="650px">
|
||||
<el-checkbox-group
|
||||
v-model="exportSelectedOptions"
|
||||
style="margin-bottom: 10px"
|
||||
@@ -26,7 +26,7 @@
|
||||
<el-dropdown-item style="display: block; margin: 10px 0" @click.native="selectWorldExportGroup(null)">
|
||||
None
|
||||
</el-dropdown-item>
|
||||
<template v-for="groupAPI in API.favoriteWorldGroups">
|
||||
<template v-for="groupAPI in favoriteWorldGroups">
|
||||
<el-dropdown-item
|
||||
:key="groupAPI.name"
|
||||
style="display: block; margin: 10px 0"
|
||||
@@ -81,151 +81,157 @@
|
||||
</safe-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'WorldExportDialog',
|
||||
inject: ['API'],
|
||||
props: {
|
||||
favoriteWorlds: Array,
|
||||
worldExportDialogVisible: Boolean,
|
||||
localWorldFavorites: Object,
|
||||
localWorldFavoriteGroups: Array,
|
||||
localWorldFavoritesList: Array
|
||||
<script setup>
|
||||
import { ref, computed, watch, getCurrentInstance } from 'vue';
|
||||
import { useI18n } from 'vue-i18n-bridge';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useFavoriteStore, useWorldStore } from '../../../stores';
|
||||
|
||||
const props = defineProps({
|
||||
worldExportDialogVisible: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:WorldExportDialogVisible']);
|
||||
|
||||
const { t } = useI18n();
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
const favoriteStore = useFavoriteStore();
|
||||
const {
|
||||
favoriteWorlds,
|
||||
favoriteWorldGroups,
|
||||
localWorldFavorites,
|
||||
localWorldFavoriteGroups,
|
||||
localWorldFavoritesList
|
||||
} = storeToRefs(favoriteStore);
|
||||
const { getLocalWorldFavoriteGroupLength } = favoriteStore;
|
||||
const { cachedWorlds } = storeToRefs(useWorldStore());
|
||||
|
||||
const worldExportContent = ref('');
|
||||
const worldExportFavoriteGroup = ref(null);
|
||||
const worldExportLocalFavoriteGroup = ref(null);
|
||||
// Storage of selected filtering options for model and world export
|
||||
const exportSelectedOptions = ref(['ID', 'Name']);
|
||||
const exportSelectOptions = ref([
|
||||
{ label: 'ID', value: 'id' },
|
||||
{ label: 'Name', value: 'name' },
|
||||
{ label: 'Author ID', value: 'authorId' },
|
||||
{ label: 'Author Name', value: 'authorName' },
|
||||
{ label: 'Thumbnail', value: 'thumbnailImageUrl' }
|
||||
]);
|
||||
|
||||
const isDialogVisible = computed({
|
||||
get() {
|
||||
return props.worldExportDialogVisible;
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
worldExportContent: '',
|
||||
worldExportFavoriteGroup: null,
|
||||
worldExportLocalFavoriteGroup: null,
|
||||
// Storage of selected filtering options for model and world export
|
||||
exportSelectedOptions: ['ID', 'Name'],
|
||||
exportSelectOptions: [
|
||||
{ label: 'ID', value: 'id' },
|
||||
{ label: 'Name', value: 'name' },
|
||||
{ label: 'Author ID', value: 'authorId' },
|
||||
{ label: 'Author Name', value: 'authorName' },
|
||||
{ label: 'Thumbnail', value: 'thumbnailImageUrl' }
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isDialogVisible: {
|
||||
get() {
|
||||
return this.worldExportDialogVisible;
|
||||
},
|
||||
set(value) {
|
||||
this.$emit('update:world-export-dialog-visible', value);
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
worldExportDialogVisible(value) {
|
||||
if (value) {
|
||||
this.showWorldExportDialog();
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showWorldExportDialog() {
|
||||
this.worldExportFavoriteGroup = null;
|
||||
this.worldExportLocalFavoriteGroup = null;
|
||||
this.updateWorldExportDialog();
|
||||
},
|
||||
set(value) {
|
||||
emit('update:WorldExportDialogVisible', value);
|
||||
}
|
||||
});
|
||||
|
||||
handleCopyWorldExportData(event) {
|
||||
if (event.target.tagName === 'TEXTAREA') {
|
||||
event.target.select();
|
||||
}
|
||||
navigator.clipboard
|
||||
.writeText(this.worldExportContent)
|
||||
.then(() => {
|
||||
this.$message({
|
||||
message: 'Copied successfully!',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Copy failed:', err);
|
||||
this.$message.error('Copy failed!');
|
||||
});
|
||||
},
|
||||
|
||||
updateWorldExportDialog() {
|
||||
const formatter = function (str) {
|
||||
if (/[\x00-\x1f,"]/.test(str) === true) {
|
||||
return `"${str.replace(/"/g, '""')}"`;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const propsForQuery = this.exportSelectOptions
|
||||
.filter((option) => this.exportSelectedOptions.includes(option.label))
|
||||
.map((option) => option.value);
|
||||
|
||||
function resText(ref) {
|
||||
let resArr = [];
|
||||
propsForQuery.forEach((e) => {
|
||||
resArr.push(formatter(ref?.[e]));
|
||||
});
|
||||
return resArr.join(',');
|
||||
}
|
||||
|
||||
const lines = [this.exportSelectedOptions.join(',')];
|
||||
|
||||
if (this.worldExportFavoriteGroup) {
|
||||
this.API.favoriteWorldGroups.forEach((group) => {
|
||||
if (this.worldExportFavoriteGroup === group) {
|
||||
this.favoriteWorlds.forEach((ref) => {
|
||||
if (group.key === ref.groupKey) {
|
||||
lines.push(resText(ref.ref));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (this.worldExportLocalFavoriteGroup) {
|
||||
const favoriteGroup = this.localWorldFavorites[this.worldExportLocalFavoriteGroup];
|
||||
if (!favoriteGroup) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < favoriteGroup.length; ++i) {
|
||||
const ref = favoriteGroup[i];
|
||||
lines.push(resText(ref));
|
||||
}
|
||||
} else {
|
||||
// export all
|
||||
this.favoriteWorlds.forEach((ref) => {
|
||||
lines.push(resText(ref.ref));
|
||||
});
|
||||
for (let i = 0; i < this.localWorldFavoritesList.length; ++i) {
|
||||
const worldId = this.localWorldFavoritesList[i];
|
||||
const ref = this.API.cachedWorlds.get(worldId);
|
||||
if (typeof ref !== 'undefined') {
|
||||
lines.push(resText(ref));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.worldExportContent = lines.join('\n');
|
||||
},
|
||||
|
||||
selectWorldExportGroup(group) {
|
||||
this.worldExportFavoriteGroup = group;
|
||||
this.worldExportLocalFavoriteGroup = null;
|
||||
this.updateWorldExportDialog();
|
||||
},
|
||||
|
||||
selectWorldExportLocalGroup(group) {
|
||||
this.worldExportLocalFavoriteGroup = group;
|
||||
this.worldExportFavoriteGroup = null;
|
||||
this.updateWorldExportDialog();
|
||||
},
|
||||
getLocalWorldFavoriteGroupLength(group) {
|
||||
const favoriteGroup = this.localWorldFavorites[group];
|
||||
if (!favoriteGroup) {
|
||||
return 0;
|
||||
}
|
||||
return favoriteGroup.length;
|
||||
watch(
|
||||
() => props.worldExportDialogVisible,
|
||||
(value) => {
|
||||
if (value) {
|
||||
showWorldExportDialog();
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
function showWorldExportDialog() {
|
||||
worldExportFavoriteGroup.value = null;
|
||||
worldExportLocalFavoriteGroup.value = null;
|
||||
updateWorldExportDialog();
|
||||
}
|
||||
|
||||
function handleCopyWorldExportData(event) {
|
||||
if (event.target.tagName === 'TEXTAREA') {
|
||||
event.target.select();
|
||||
}
|
||||
navigator.clipboard
|
||||
.writeText(worldExportContent.value)
|
||||
.then(() => {
|
||||
proxy.$message({
|
||||
message: 'Copied successfully!',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Copy failed:', err);
|
||||
proxy.$message.error('Copy failed!');
|
||||
});
|
||||
}
|
||||
|
||||
function updateWorldExportDialog() {
|
||||
const formatter = function (str) {
|
||||
if (/[\x00-\x1f,"]/.test(str) === true) {
|
||||
return `"${str.replace(/"/g, '""')}"`;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const propsForQuery = exportSelectOptions.value
|
||||
.filter((option) => exportSelectedOptions.value.includes(option.label))
|
||||
.map((option) => option.value);
|
||||
|
||||
function resText(ref) {
|
||||
let resArr = [];
|
||||
propsForQuery.forEach((e) => {
|
||||
resArr.push(formatter(ref?.[e]));
|
||||
});
|
||||
return resArr.join(',');
|
||||
}
|
||||
|
||||
const lines = [exportSelectedOptions.value.join(',')];
|
||||
|
||||
if (worldExportFavoriteGroup.value) {
|
||||
favoriteWorldGroups.value.forEach((group) => {
|
||||
if (worldExportFavoriteGroup.value === group) {
|
||||
favoriteWorlds.value.forEach((ref) => {
|
||||
if (group.key === ref.groupKey) {
|
||||
lines.push(resText(ref.ref));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (worldExportLocalFavoriteGroup.value) {
|
||||
const favoriteGroup = localWorldFavorites.value[worldExportLocalFavoriteGroup.value];
|
||||
if (!favoriteGroup) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < favoriteGroup.length; ++i) {
|
||||
const ref = favoriteGroup[i];
|
||||
lines.push(resText(ref));
|
||||
}
|
||||
} else {
|
||||
// export all
|
||||
favoriteWorlds.value.forEach((ref) => {
|
||||
lines.push(resText(ref.ref));
|
||||
});
|
||||
for (let i = 0; i < localWorldFavoritesList.value.length; ++i) {
|
||||
const worldId = localWorldFavoritesList.value[i];
|
||||
const ref = cachedWorlds.value.get(worldId);
|
||||
if (typeof ref !== 'undefined') {
|
||||
lines.push(resText(ref));
|
||||
}
|
||||
}
|
||||
}
|
||||
worldExportContent.value = lines.join('\n');
|
||||
}
|
||||
|
||||
function selectWorldExportGroup(group) {
|
||||
worldExportFavoriteGroup.value = group;
|
||||
worldExportLocalFavoriteGroup.value = null;
|
||||
updateWorldExportDialog();
|
||||
}
|
||||
|
||||
function selectWorldExportLocalGroup(group) {
|
||||
worldExportLocalFavoriteGroup.value = group;
|
||||
worldExportFavoriteGroup.value = null;
|
||||
updateWorldExportDialog();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
<template>
|
||||
<safe-dialog
|
||||
ref="worldImportDialog"
|
||||
ref="worldImportDialogRef"
|
||||
:visible.sync="isVisible"
|
||||
:title="$t('dialog.world_import.header')"
|
||||
:title="t('dialog.world_import.header')"
|
||||
width="650px"
|
||||
top="10vh"
|
||||
class="x-dialog">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between">
|
||||
<div style="font-size: 12px">{{ $t('dialog.world_import.description') }}</div>
|
||||
<div style="font-size: 12px">{{ t('dialog.world_import.description') }}</div>
|
||||
<div style="display: flex; align-items: center">
|
||||
<div v-if="worldImportDialog.progress">
|
||||
{{ $t('dialog.world_import.process_progress') }}
|
||||
{{ t('dialog.world_import.process_progress') }}
|
||||
{{ worldImportDialog.progress }} / {{ worldImportDialog.progressTotal }}
|
||||
<i class="el-icon-loading" style="margin: 0 5px"></i>
|
||||
</div>
|
||||
<el-button v-if="worldImportDialog.loading" size="small" @click="cancelWorldImport">
|
||||
{{ $t('dialog.world_import.cancel') }}
|
||||
{{ t('dialog.world_import.cancel') }}
|
||||
</el-button>
|
||||
<el-button v-else size="small" :disabled="!worldImportDialog.input" @click="processWorldImportList">
|
||||
{{ $t('dialog.world_import.process_list') }}
|
||||
{{ t('dialog.world_import.process_list') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -41,12 +41,12 @@
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ $t('dialog.world_import.select_vrchat_group_placeholder') }}
|
||||
{{ t('dialog.world_import.select_vrchat_group_placeholder') }}
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
</el-button>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<template v-for="groupAPI in API.favoriteWorldGroups">
|
||||
<template v-for="groupAPI in favoriteWorldGroups">
|
||||
<el-dropdown-item
|
||||
:key="groupAPI.name"
|
||||
style="display: block; margin: 10px 0"
|
||||
@@ -65,7 +65,7 @@
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ $t('dialog.world_import.select_local_group_placeholder') }}
|
||||
{{ t('dialog.world_import.select_local_group_placeholder') }}
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</span>
|
||||
</el-button>
|
||||
@@ -90,7 +90,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<el-button size="small" :disabled="worldImportTable.data.length === 0" @click="clearWorldImportTable">
|
||||
{{ $t('dialog.world_import.clear_table') }}
|
||||
{{ t('dialog.world_import.clear_table') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
@@ -102,27 +102,27 @@
|
||||
!worldImportDialog.worldImportLocalFavoriteGroup)
|
||||
"
|
||||
@click="importWorldImportTable">
|
||||
{{ $t('dialog.world_import.import') }}
|
||||
{{ t('dialog.world_import.import') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<span v-if="worldImportDialog.importProgress" style="margin: 10px">
|
||||
<i class="el-icon-loading" style="margin-right: 5px"></i>
|
||||
{{ $t('dialog.world_import.import_progress') }}
|
||||
{{ t('dialog.world_import.import_progress') }}
|
||||
{{ worldImportDialog.importProgress }}/{{ worldImportDialog.importProgressTotal }}
|
||||
</span>
|
||||
<br />
|
||||
<template v-if="worldImportDialog.errors">
|
||||
<el-button size="small" @click="worldImportDialog.errors = ''">
|
||||
{{ $t('dialog.world_import.clear_errors') }}
|
||||
{{ t('dialog.world_import.clear_errors') }}
|
||||
</el-button>
|
||||
<h2 style="font-weight: bold; margin: 5px 0">
|
||||
{{ $t('dialog.world_import.errors') }}
|
||||
{{ t('dialog.world_import.errors') }}
|
||||
</h2>
|
||||
<pre style="white-space: pre-wrap; font-size: 12px" v-text="worldImportDialog.errors"></pre>
|
||||
</template>
|
||||
<data-tables v-loading="worldImportDialog.loading" v-bind="worldImportTable" style="margin-top: 10px">
|
||||
<el-table-column :label="$t('table.import.image')" width="70" prop="thumbnailImageUrl">
|
||||
<el-table-column :label="t('table.import.image')" width="70" prop="thumbnailImageUrl">
|
||||
<template slot-scope="scope">
|
||||
<el-popover placement="right" height="500px" trigger="hover">
|
||||
<img slot="reference" v-lazy="scope.row.thumbnailImageUrl" class="friends-list-avatar" />
|
||||
@@ -134,12 +134,12 @@
|
||||
</el-popover>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.name')" prop="name">
|
||||
<el-table-column :label="t('table.import.name')" prop="name">
|
||||
<template slot-scope="scope">
|
||||
<span class="x-link" @click="showWorldDialog(scope.row.id)" v-text="scope.row.name"></span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.author')" width="120" prop="authorName">
|
||||
<el-table-column :label="t('table.import.author')" width="120" prop="authorName">
|
||||
<template slot-scope="scope">
|
||||
<span
|
||||
class="x-link"
|
||||
@@ -147,7 +147,7 @@
|
||||
v-text="scope.row.authorName"></span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.status')" width="70" prop="releaseStatus">
|
||||
<el-table-column :label="t('table.import.status')" width="70" prop="releaseStatus">
|
||||
<template slot-scope="scope">
|
||||
<span
|
||||
:style="{
|
||||
@@ -163,7 +163,7 @@
|
||||
"></span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('table.import.action')" width="90" align="right">
|
||||
<el-table-column :label="t('table.import.action')" width="90" align="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
type="text"
|
||||
@@ -176,185 +176,193 @@
|
||||
</safe-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script setup>
|
||||
import { ref, watch, computed, getCurrentInstance } from 'vue';
|
||||
import { useI18n } from 'vue-i18n-bridge';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { favoriteRequest, worldRequest } from '../../../api';
|
||||
import utils from '../../../classes/utils';
|
||||
import { adjustDialogZ, removeFromArray } from '../../../shared/utils';
|
||||
import { useFavoriteStore, useGalleryStore, useUserStore, useWorldStore } from '../../../stores';
|
||||
|
||||
export default {
|
||||
name: 'WorldImportDialog',
|
||||
inject: ['API', 'showFullscreenImageDialog', 'showUserDialog', 'adjustDialogZ', 'showWorldDialog'],
|
||||
props: {
|
||||
worldImportDialogVisible: Boolean,
|
||||
worldImportDialogInput: String,
|
||||
getLocalWorldFavoriteGroupLength: Function,
|
||||
localWorldFavoriteGroups: Array
|
||||
const { showUserDialog } = useUserStore();
|
||||
const { favoriteWorldGroups, worldImportDialogInput, worldImportDialogVisible, localWorldFavoriteGroups } =
|
||||
storeToRefs(useFavoriteStore());
|
||||
const { getLocalWorldFavoriteGroupLength, addLocalWorldFavorite } = useFavoriteStore();
|
||||
const { showWorldDialog } = useWorldStore();
|
||||
const { showFullscreenImageDialog } = useGalleryStore();
|
||||
|
||||
const emit = defineEmits(['update:worldImportDialogInput']);
|
||||
|
||||
const { proxy } = getCurrentInstance();
|
||||
const { t } = useI18n();
|
||||
|
||||
const worldImportDialogRef = ref(null);
|
||||
|
||||
const worldImportDialog = ref({
|
||||
loading: false,
|
||||
progress: 0,
|
||||
progressTotal: 0,
|
||||
input: '',
|
||||
worldIdList: new Set(),
|
||||
errors: '',
|
||||
worldImportFavoriteGroup: null,
|
||||
worldImportLocalFavoriteGroup: null,
|
||||
importProgress: 0,
|
||||
importProgressTotal: 0
|
||||
});
|
||||
|
||||
const worldImportTable = ref({
|
||||
data: [],
|
||||
tableProps: {
|
||||
stripe: true,
|
||||
size: 'mini'
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
worldImportDialog: {
|
||||
loading: false,
|
||||
progress: 0,
|
||||
progressTotal: 0,
|
||||
input: '',
|
||||
worldIdList: new Set(),
|
||||
errors: '',
|
||||
worldImportFavoriteGroup: null,
|
||||
worldImportLocalFavoriteGroup: null,
|
||||
importProgress: 0,
|
||||
importProgressTotal: 0
|
||||
},
|
||||
worldImportTable: {
|
||||
data: [],
|
||||
tableProps: {
|
||||
stripe: true,
|
||||
size: 'mini'
|
||||
},
|
||||
layout: 'table'
|
||||
}
|
||||
};
|
||||
layout: 'table'
|
||||
});
|
||||
|
||||
const isVisible = computed({
|
||||
get() {
|
||||
return worldImportDialogVisible.value;
|
||||
},
|
||||
computed: {
|
||||
isVisible: {
|
||||
get() {
|
||||
return this.worldImportDialogVisible;
|
||||
},
|
||||
set(visible) {
|
||||
this.$emit('update:world-import-dialog-visible', visible);
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
worldImportDialogVisible(visible) {
|
||||
if (visible) {
|
||||
this.adjustDialogZ(this.$refs.worldImportDialog.$el);
|
||||
this.clearWorldImportTable();
|
||||
this.resetWorldImport();
|
||||
if (this.worldImportDialogInput) {
|
||||
this.worldImportDialog.input = this.worldImportDialogInput;
|
||||
this.processWorldImportList();
|
||||
this.$emit('update:world-import-dialog-input', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
resetWorldImport() {
|
||||
this.worldImportDialog.input = '';
|
||||
this.worldImportDialog.errors = '';
|
||||
},
|
||||
async processWorldImportList() {
|
||||
const D = this.worldImportDialog;
|
||||
D.loading = true;
|
||||
const regexWorldId = /wrld_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
|
||||
let match = [];
|
||||
const worldIdList = new Set();
|
||||
while ((match = regexWorldId.exec(D.input)) !== null) {
|
||||
worldIdList.add(match[0]);
|
||||
}
|
||||
D.input = '';
|
||||
D.errors = '';
|
||||
D.progress = 0;
|
||||
D.progressTotal = worldIdList.size;
|
||||
const data = Array.from(worldIdList);
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
if (!this.isVisible) {
|
||||
this.resetWorldImport();
|
||||
}
|
||||
if (!D.loading || !this.isVisible) {
|
||||
break;
|
||||
}
|
||||
const worldId = data[i];
|
||||
if (!D.worldIdList.has(worldId)) {
|
||||
try {
|
||||
const args = await worldRequest.getWorld({
|
||||
worldId
|
||||
});
|
||||
this.worldImportTable.data.push(args.ref);
|
||||
D.worldIdList.add(worldId);
|
||||
} catch (err) {
|
||||
D.errors = D.errors.concat(`WorldId: ${worldId}\n${err}\n\n`);
|
||||
}
|
||||
}
|
||||
D.progress++;
|
||||
if (D.progress === worldIdList.size) {
|
||||
D.progress = 0;
|
||||
}
|
||||
}
|
||||
D.loading = false;
|
||||
},
|
||||
deleteItemWorldImport(ref) {
|
||||
utils.removeFromArray(this.worldImportTable.data, ref);
|
||||
this.worldImportDialog.worldIdList.delete(ref.id);
|
||||
},
|
||||
set(visible) {
|
||||
worldImportDialogVisible.value = visible;
|
||||
}
|
||||
});
|
||||
|
||||
clearWorldImportTable() {
|
||||
this.worldImportTable.data = [];
|
||||
this.worldImportDialog.worldIdList = new Set();
|
||||
},
|
||||
|
||||
selectWorldImportGroup(group) {
|
||||
this.worldImportDialog.worldImportLocalFavoriteGroup = null;
|
||||
this.worldImportDialog.worldImportFavoriteGroup = group;
|
||||
},
|
||||
|
||||
selectWorldImportLocalGroup(group) {
|
||||
this.worldImportDialog.worldImportFavoriteGroup = null;
|
||||
this.worldImportDialog.worldImportLocalFavoriteGroup = group;
|
||||
},
|
||||
|
||||
cancelWorldImport() {
|
||||
this.worldImportDialog.loading = false;
|
||||
},
|
||||
|
||||
async importWorldImportTable() {
|
||||
const D = this.worldImportDialog;
|
||||
if (!D.worldImportFavoriteGroup && !D.worldImportLocalFavoriteGroup) {
|
||||
return;
|
||||
watch(
|
||||
() => worldImportDialogVisible.value,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
adjustDialogZ(worldImportDialogRef.value.$el);
|
||||
clearWorldImportTable();
|
||||
resetWorldImport();
|
||||
if (worldImportDialogInput.value) {
|
||||
worldImportDialog.value.input = worldImportDialogInput.value;
|
||||
processWorldImportList();
|
||||
emit('update:worldImportDialogInput', '');
|
||||
}
|
||||
D.loading = true;
|
||||
const data = [...this.worldImportTable.data].reverse();
|
||||
D.importProgressTotal = data.length;
|
||||
let ref = '';
|
||||
try {
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
if (!D.loading || !this.isVisible) {
|
||||
break;
|
||||
}
|
||||
ref = data[i];
|
||||
if (D.worldImportFavoriteGroup) {
|
||||
await this.addFavoriteWorld(ref, D.worldImportFavoriteGroup, false);
|
||||
} else if (D.worldImportLocalFavoriteGroup) {
|
||||
this.$emit('addLocalWorldFavorite', ref.id, D.worldImportLocalFavoriteGroup);
|
||||
}
|
||||
utils.removeFromArray(this.worldImportTable.data, ref);
|
||||
D.worldIdList.delete(ref.id);
|
||||
D.importProgress++;
|
||||
}
|
||||
} catch (err) {
|
||||
D.errors = `Name: ${ref.name}\nWorldId: ${ref.id}\n${err}\n\n`;
|
||||
} finally {
|
||||
D.importProgress = 0;
|
||||
D.importProgressTotal = 0;
|
||||
D.loading = false;
|
||||
}
|
||||
},
|
||||
addFavoriteWorld(ref, group, message) {
|
||||
return favoriteRequest
|
||||
.addFavorite({
|
||||
type: 'world',
|
||||
favoriteId: ref.id,
|
||||
tags: group.name
|
||||
})
|
||||
.then((args) => {
|
||||
if (message) {
|
||||
this.$message({
|
||||
message: 'World added to favorites',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
return args;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
function resetWorldImport() {
|
||||
worldImportDialog.value.input = '';
|
||||
worldImportDialog.value.errors = '';
|
||||
}
|
||||
|
||||
async function processWorldImportList() {
|
||||
const D = worldImportDialog.value;
|
||||
D.loading = true;
|
||||
const regexWorldId = /wrld_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
|
||||
let match = [];
|
||||
const worldIdList = new Set();
|
||||
while ((match = regexWorldId.exec(D.input)) !== null) {
|
||||
worldIdList.add(match[0]);
|
||||
}
|
||||
D.input = '';
|
||||
D.errors = '';
|
||||
D.progress = 0;
|
||||
D.progressTotal = worldIdList.size;
|
||||
const data = Array.from(worldIdList);
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
if (!isVisible.value) {
|
||||
resetWorldImport();
|
||||
}
|
||||
if (!D.loading || !isVisible.value) {
|
||||
break;
|
||||
}
|
||||
const worldId = data[i];
|
||||
if (!D.worldIdList.has(worldId)) {
|
||||
try {
|
||||
const args = await worldRequest.getWorld({
|
||||
worldId
|
||||
});
|
||||
worldImportTable.value.data.push(args.ref);
|
||||
D.worldIdList.add(worldId);
|
||||
} catch (err) {
|
||||
D.errors = D.errors.concat(`WorldId: ${worldId}\n${err}\n\n`);
|
||||
}
|
||||
}
|
||||
D.progress++;
|
||||
if (D.progress === worldIdList.size) {
|
||||
D.progress = 0;
|
||||
}
|
||||
}
|
||||
D.loading = false;
|
||||
}
|
||||
|
||||
function deleteItemWorldImport(ref) {
|
||||
removeFromArray(worldImportTable.value.data, ref);
|
||||
worldImportDialog.value.worldIdList.delete(ref.id);
|
||||
}
|
||||
|
||||
function clearWorldImportTable() {
|
||||
worldImportTable.value.data = [];
|
||||
worldImportDialog.value.worldIdList = new Set();
|
||||
}
|
||||
|
||||
function selectWorldImportGroup(group) {
|
||||
worldImportDialog.value.worldImportLocalFavoriteGroup = null;
|
||||
worldImportDialog.value.worldImportFavoriteGroup = group;
|
||||
}
|
||||
|
||||
function selectWorldImportLocalGroup(group) {
|
||||
worldImportDialog.value.worldImportFavoriteGroup = null;
|
||||
worldImportDialog.value.worldImportLocalFavoriteGroup = group;
|
||||
}
|
||||
|
||||
function cancelWorldImport() {
|
||||
worldImportDialog.value.loading = false;
|
||||
}
|
||||
|
||||
async function importWorldImportTable() {
|
||||
const D = worldImportDialog.value;
|
||||
if (!D.worldImportFavoriteGroup && !D.worldImportLocalFavoriteGroup) {
|
||||
return;
|
||||
}
|
||||
D.loading = true;
|
||||
const data = [...worldImportTable.value.data].reverse();
|
||||
D.importProgressTotal = data.length;
|
||||
let ref = '';
|
||||
try {
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
if (!D.loading || !isVisible.value) {
|
||||
break;
|
||||
}
|
||||
ref = data[i];
|
||||
if (D.worldImportFavoriteGroup) {
|
||||
await addFavoriteWorld(ref, D.worldImportFavoriteGroup, false);
|
||||
} else if (D.worldImportLocalFavoriteGroup) {
|
||||
addLocalWorldFavorite(ref, D.worldImportLocalFavoriteGroup);
|
||||
}
|
||||
removeFromArray(worldImportTable.value.data, ref);
|
||||
D.worldIdList.delete(ref.id);
|
||||
D.importProgress++;
|
||||
}
|
||||
} catch (err) {
|
||||
D.errors = `Name: ${ref.name}\nWorldId: ${ref.id}\n${err}\n\n`;
|
||||
} finally {
|
||||
D.importProgress = 0;
|
||||
D.importProgressTotal = 0;
|
||||
D.loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function addFavoriteWorld(ref, group, message) {
|
||||
return favoriteRequest
|
||||
.addFavorite({
|
||||
type: 'world',
|
||||
favoriteId: ref.id,
|
||||
tags: group.name
|
||||
})
|
||||
.then((args) => {
|
||||
if (message) {
|
||||
proxy.$message({
|
||||
message: 'World added to favorites',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
return args;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user