diff --git a/public/config.js b/public/config.js
index 129f721..fb731ca 100644
--- a/public/config.js
+++ b/public/config.js
@@ -3,7 +3,7 @@ window.$$nazhuaConfig = {
// freeAmount: '白嫖', // 免费服务的费用名称
// infinityCycle: '长期有效', // 无限周期名称
// buyBtnText: '购买', // 购买按钮文案
- // listServerItemType: 'row', // 服务器列表项类型 card/row row列表模式目前为体验版不兼容移动端
+ // listServerItemType: 'row', // 服务器列表项类型 card/row row列表模式移动端自动切换至card
// listServerStatusType: 'progress', // 服务器状态类型--列表
// listServerRealTimeShowLoad: false, // 列表显示服务器实时负载
// detailServerStatusType: 'progress', // 服务器状态类型--详情页
diff --git a/src/store/index.js b/src/store/index.js
index 328d71f..5ee70e5 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -21,6 +21,7 @@ const defaultState = () => ({
serverTime: 0,
serverGroup: [],
serverList: [],
+ serverListColumnWidths: {},
serverCount: {
total: 0,
online: 0,
@@ -92,6 +93,9 @@ const store = createStore({
SET_SETTING(state, setting) {
state.setting = setting;
},
+ SET_SERVER_LIST_COLUMN_WIDTHS(state, widths) {
+ state.serverListColumnWidths = widths;
+ },
},
actions: {
/**
@@ -184,6 +188,33 @@ const store = createStore({
}
});
},
+ /**
+ * 设置服务器列表行宽度
+ */
+ setServerListColumnWidths({
+ commit,
+ state,
+ }, data) {
+ const newWidths = {
+ ...state.serverListColumnWidths,
+ ...data,
+ };
+ commit('SET_SERVER_LIST_COLUMN_WIDTHS', newWidths);
+ },
+ setServerListColumnWidth({
+ commit,
+ state,
+ }, data) {
+ const newWidths = {
+ ...state.serverListColumnWidths,
+ };
+ if (newWidths[data.prop]) {
+ newWidths[data.prop] = Math.max(newWidths[data.prop], data.width);
+ } else {
+ newWidths[data.prop] = data.width;
+ }
+ commit('SET_SERVER_LIST_COLUMN_WIDTHS', newWidths);
+ },
},
});
diff --git a/src/views/components/server-list/row/server-list-column.vue b/src/views/components/server-list/row/server-list-column.vue
index 34460d9..3872c91 100644
--- a/src/views/components/server-list/row/server-list-column.vue
+++ b/src/views/components/server-list/row/server-list-column.vue
@@ -4,7 +4,10 @@
:class="`list-column--${prop}`"
:style="columnStyle"
>
-
+
{{ label }}
@@ -34,7 +37,13 @@
import {
computed,
+ ref,
+ onMounted,
+ onBeforeUnmount,
} from 'vue';
+import {
+ useStore,
+} from 'vuex';
const props = defineProps({
prop: {
@@ -67,11 +76,46 @@ const props = defineProps({
},
});
+const store = useStore();
+
+const columnContentRef = ref(null);
+let resizeObserver = null;
+
+const columnWidth = computed(() => store.state?.serverListColumnWidths?.[props.prop]);
+
+onMounted(() => {
+ if (columnContentRef.value) {
+ resizeObserver = new ResizeObserver((entries) => {
+ entries.forEach((entry) => {
+ let { width } = entry.contentRect;
+ width = Math.ceil(width);
+ store.dispatch('setServerListColumnWidth', {
+ prop: props.prop,
+ width: width > 40 ? width : 40,
+ });
+ });
+ });
+
+ resizeObserver.observe(columnContentRef.value);
+ }
+});
+
+onBeforeUnmount(() => {
+ if (resizeObserver) {
+ resizeObserver.disconnect();
+ resizeObserver = null;
+ }
+});
+
const columnStyle = computed(() => {
const style = {};
- const width = parseInt(props.width, 10);
- if (Number.isNaN(width) === false) {
- style.width = `${width}px`;
+ if (props.width) {
+ const width = parseInt(props.width, 10);
+ if (Number.isNaN(width) === false) {
+ style.width = `${width}px`;
+ }
+ } else if (columnWidth.value > 0) {
+ style.width = `${columnWidth.value}px`;
}
return style;
});
@@ -79,15 +123,23 @@ const columnStyle = computed(() => {
diff --git a/src/views/home.vue b/src/views/home.vue
index 523e8f4..3ff7b38 100644
--- a/src/views/home.vue
+++ b/src/views/home.vue
@@ -13,6 +13,10 @@
-
+
+
+ {
+ if (windowWidth.value > 1024) {
+ return config.nazhua.listServerItemType === 'row';
+ }
+ return false;
+});
+const showListCard = computed(() => {
+ if (windowWidth.value > 1024) {
+ return config.nazhua.listServerItemType !== 'row';
+ }
+ return true;
+});
const showFilter = computed(() => config.nazhua.hideFilter !== true);
const filterFormData = ref({
@@ -246,6 +268,7 @@ const showWorldMap = computed(() => {
*/
function handleResize() {
worldMapWidth.value = document.querySelector('.server-list-container').clientWidth - 40;
+ windowWidth.value = window.innerWidth;
}
onMounted(() => {
@@ -285,6 +308,10 @@ onUnmounted(() => {
gap: 10px 20px;
width: var(--list-container-width);
margin: auto;
+
+ &.list-is-card {
+ padding: 0 20px;
+ }
}
.server-list-container.server-list--card {