refactor(page-decoration): 用 beforeRelease 替换发布开关逻辑

- 楼层与移动端装修列表改用 before-change,避免开关被直接切换
- 唯一页面禁止关闭,已开启页面提示改开其他页
- 按接口成功/失败再决定是否切换开关
This commit is contained in:
田香琪
2026-09-24 17:45:46 +08:00
parent ff38cf52b4
commit 54c72239d4
5 changed files with 89 additions and 33 deletions

View File

@@ -32,7 +32,7 @@
inline-prompt inline-prompt
active-text="开" active-text="开"
inactive-text="关" inactive-text="关"
@change="releaseTemplate(row.id)" :before-change="() => beforeRelease(row)"
/> />
</template> </template>
</el-table-column> </el-table-column>
@@ -200,12 +200,27 @@ export default {
}); });
}, },
releaseTemplate(id) { beforeRelease(row) {
API_floor.releasePageHome(id).then((res) => { if (row.pageShow) {
if (res.success) { this.$Message.warning(
this.$Message.success("发布模板成功"); this.total === 1
this.getTemplateList(); ? "当前为唯一页面,无法关闭"
} : "请直接开启其他页面,当前页面会自动关闭"
);
return false;
}
return new Promise((resolve, reject) => {
API_floor.releasePageHome(row.id).then((res) => {
if (res && res.success) {
this.$Message.success("发布模板成功");
resolve(true);
this.getTemplateList();
} else {
reject(new Error("release failed"));
}
}).catch(() => {
reject(new Error("release failed"));
});
}); });
}, },
confirmDel(id) { confirmDel(id) {

View File

@@ -27,7 +27,7 @@
inline-prompt inline-prompt
active-text="开" active-text="开"
inactive-text="关" inactive-text="关"
@change="changeSwitch(row)" :before-change="() => beforeRelease(row)"
/> />
</template> </template>
</el-table-column> </el-table-column>
@@ -107,14 +107,27 @@ export default {
this.params.pageNumber = val; this.params.pageNumber = val;
this.init(); this.init();
}, },
changeSwitch(item) { beforeRelease(row) {
this.loading = true; if (row.pageShow) {
API_Other.releasePageHome(item.id).then((res) => { this.$Message.warning(
this.loading = false; this.total === 1
if (res.result) { ? "当前为唯一页面,无法关闭"
this.$Message.success("发布成功"); : "请直接开启其他页面,当前页面会自动关闭"
this.init(); );
} return false;
}
return new Promise((resolve, reject) => {
API_Other.releasePageHome(row.id).then((res) => {
if (res && res.success) {
this.$Message.success("发布成功");
resolve(true);
this.init();
} else {
reject(new Error("release failed"));
}
}).catch(() => {
reject(new Error("release failed"));
});
}); });
}, },
init() { init() {

View File

@@ -1,4 +1,4 @@
import { sellerUrl, getRequest, uploadFileRequest, uploadFile, request} from "@/libs/axios"; import { sellerUrl, getRequest, uploadFileRequest, uploadFile } from "@/libs/axios";
// 通过id获取子地区 // 通过id获取子地区
export const getChildRegion = (id) => { export const getChildRegion = (id) => {

View File

@@ -31,7 +31,7 @@
inline-prompt inline-prompt
active-text="开" active-text="开"
inactive-text="关" inactive-text="关"
@change="releaseTemplate(row.id)" :before-change="() => beforeRelease(row)"
/> />
</template> </template>
</el-table-column> </el-table-column>
@@ -195,12 +195,27 @@ export default {
}); });
}, },
releaseTemplate(id) { beforeRelease(row) {
API_floor.releasePageHome(id).then((res) => { if (row.pageShow) {
if (res.success) { this.$Message.warning(
this.$Message.success("发布模板成功"); this.total === 1
this.getTemplateList(); ? "当前为唯一页面,无法关闭"
} : "请直接开启其他页面,当前页面会自动关闭"
);
return false;
}
return new Promise((resolve, reject) => {
API_floor.releasePageHome(row.id).then((res) => {
if (res && res.success) {
this.$Message.success("发布模板成功");
resolve(true);
this.getTemplateList();
} else {
reject(new Error("release failed"));
}
}).catch(() => {
reject(new Error("release failed"));
});
}); });
}, },
confirmDel(id) { confirmDel(id) {

View File

@@ -26,7 +26,7 @@
inline-prompt inline-prompt
active-text="开" active-text="开"
inactive-text="关" inactive-text="关"
@change="changeSwitch(row)" :before-change="() => beforeRelease(row)"
/> />
</template> </template>
</el-table-column> </el-table-column>
@@ -106,14 +106,27 @@ export default {
this.params.pageNumber = val; this.params.pageNumber = val;
this.init(); this.init();
}, },
changeSwitch(item) { beforeRelease(row) {
this.loading = true; if (row.pageShow) {
API_Other.releasePageHome(item.id).then((res) => { this.$Message.warning(
this.loading = false; this.total === 1
if (res.result) { ? "当前为唯一页面,无法关闭"
this.$Message.success("发布成功"); : "请直接开启其他页面,当前页面会自动关闭"
this.init(); );
} return false;
}
return new Promise((resolve, reject) => {
API_Other.releasePageHome(row.id).then((res) => {
if (res && res.success) {
this.$Message.success("发布成功");
resolve(true);
this.init();
} else {
reject(new Error("release failed"));
}
}).catch(() => {
reject(new Error("release failed"));
});
}); });
}, },
init() { init() {