feat: 添加新建名片按钮,更新空状态提示信息

This commit is contained in:
2026-10-13 10:29:07 +08:00
parent f22892968f
commit 6e3818dff6
2 changed files with 44 additions and 11 deletions

View File

@@ -190,6 +190,8 @@ export default {
data() {
return {
cardId: '',
// 新建模式: 无 card_id 进入, 提交 /card/api/card/create
isCreate: false,
form: {
name: '', company: '', job_title: '', avatar: '',
mobile: '', phone: '', email: '', website: '', wechat: '',
@@ -209,7 +211,12 @@ export default {
},
onLoad(options) {
this.cardId = decodeURIComponent(options.card_id || '');
this.loadDetail();
this.isCreate = this.cardId === '';
if (this.isCreate) {
uni.setNavigationBarTitle({ title: '新建名片' });
} else {
this.loadDetail();
}
},
methods: {
loadDetail() {
@@ -372,18 +379,32 @@ export default {
value: String(c.value || '').trim()
}));
const payload = { fields: fields };
if (!this.isCreate) payload.card_id = this.cardId;
this.$api.sendJson({
url: '/card/api/card/update',
data: {
card_id: this.cardId,
fields: fields
},
url: this.isCreate ? '/card/api/card/create' : '/card/api/card/update',
data: payload,
success: res => {
this.saving = false;
if (res.code == 0) {
uni.showToast({ title: '保存成功', icon: 'success' });
// 返回详情页; detail.vue 的 onShow 会自动刷新
setTimeout(() => uni.navigateBack(), 600);
uni.showToast({ title: this.isCreate ? '创建成功' : '保存成功', icon: 'success' });
if (this.isCreate) {
// 新建成功 → 跳详情页(redirectTo 替换当前编辑页, 返回栈回到列表)
const newCardId = (res.data && res.data.card_id) || '';
setTimeout(() => {
if (newCardId) {
uni.redirectTo({
url: '/pages_tool/card/detail?card_id=' + encodeURIComponent(newCardId)
});
} else {
uni.navigateBack();
}
}, 600);
} else {
// 返回详情页; detail.vue 的 onShow 会自动刷新
setTimeout(() => uni.navigateBack(), 600);
}
} else {
uni.showToast({ title: res.message || '保存失败', icon: 'none' });
}