feat: 添加新建名片按钮,更新空状态提示信息
This commit is contained in:
@@ -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' });
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<text v-if="keyword" class="search-clear" @tap="clearKeyword">✕</text>
|
||||
<text class="iconfont icon-sousuo3" @tap="onSearch"></text>
|
||||
</view>
|
||||
<view class="claim-btn create-btn" @tap="goCreate">新建</view>
|
||||
<view class="claim-btn" @tap="onClaimTap">认领</view>
|
||||
</view>
|
||||
|
||||
@@ -53,7 +54,7 @@ export default {
|
||||
count: 0,
|
||||
keyword: '',
|
||||
isLoading: false,
|
||||
emptyText: '暂无名片,点击右上角「认领」添加'
|
||||
emptyText: '暂无名片,可点击右上角「新建」或「认领」添加'
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
@@ -104,7 +105,7 @@ export default {
|
||||
this.list = pageNo === 1 ? rows : this.list.concat(rows);
|
||||
this.emptyText = this.keyword.trim()
|
||||
? '未找到匹配的名片'
|
||||
: '暂无名片,点击右上角「认领」添加';
|
||||
: '暂无名片,可点击右上角「新建」或「认领」添加';
|
||||
} else {
|
||||
this.handleApiError(res);
|
||||
}
|
||||
@@ -124,6 +125,11 @@ export default {
|
||||
url: '/pages_tool/card/detail?card_id=' + encodeURIComponent(item.card_id)
|
||||
});
|
||||
},
|
||||
goCreate() {
|
||||
uni.navigateTo({
|
||||
url: '/pages_tool/card/edit'
|
||||
});
|
||||
},
|
||||
onClaimTap() {
|
||||
uni.showModal({
|
||||
title: '认领名片',
|
||||
@@ -228,6 +234,12 @@ export default {
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
border-radius: 36rpx;
|
||||
|
||||
/* 「新建」次级按钮: 主按钮同构, 淡底弱化一档 */
|
||||
&.create-btn {
|
||||
background-color: var(--main-color-shallow, #e8f1fb);
|
||||
color: var(--main-color, #0054a5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user