+
();
const loading = ref(false);
const syncLoading = ref(false);
+const sortMode = ref(false);
+const sortContainer = ref();
+let sortableInstance: Sortable | null = null;
let timer: NodeJS.Timer | null = null;
const paginationConfig = reactive({
cacheSizeKey: 'app-installed-page-size',
@@ -429,6 +448,61 @@ const openTerminal = (row: any) => {
dialogTerminalRef.value!.acceptParams({ containerID: row.container, title: title });
};
+const enterSortMode = async () => {
+ sortMode.value = true;
+ clearInterval(Number(timer));
+ timer = null;
+ const res = await searchAppInstalled({ page: 1, pageSize: 10000, name: '', tags: [], update: false, sync: false });
+ data.value = res.data.items;
+ await nextTick();
+ const el = sortContainer.value?.$el;
+ if (el) {
+ const favCount = data.value.filter((i: any) => i.favorite).length;
+ sortableInstance = Sortable.create(el, {
+ animation: 150,
+ ghostClass: 'sortable-ghost',
+ onMove: (evt: any) => {
+ const from = evt.dragged.dataset.sortIndex;
+ const to = evt.related.dataset.sortIndex;
+ const fromFav = Number(from) < favCount;
+ const toFav = Number(to) < favCount;
+ return fromFav === toFav;
+ },
+ onEnd: (evt: any) => {
+ const list = [...data.value];
+ const [moved] = list.splice(evt.oldIndex, 1);
+ list.splice(evt.newIndex, 0, moved);
+ data.value = list;
+ },
+ });
+ }
+};
+
+const saveSortOrder = async () => {
+ if (!data.value) return;
+ let favIdx = 0;
+ let normalIdx = 0;
+ const items = data.value.map((item: any) => ({
+ installID: item.id,
+ sortOrder: item.favorite ? favIdx++ : normalIdx++,
+ }));
+ await updateAppInstallSort(items);
+ MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
+ exitSortMode();
+};
+
+const exitSortMode = () => {
+ if (sortableInstance) {
+ sortableInstance.destroy();
+ sortableInstance = null;
+ }
+ sortMode.value = false;
+ search();
+ timer = setInterval(() => {
+ search();
+ }, 1000 * 30);
+};
+
const getConfig = async () => {
try {
const res = await getAgentSettingByKey('SystemIP');