From fdd5932a268d7f8e5194ab415c2f72c1c19cfe6c Mon Sep 17 00:00:00 2001 From: yuan Date: Tue, 9 Jan 2024 11:59:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BB=E6=AD=A2=E8=81=94=E7=B3=BB=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/contact-edit/index.vue | 39 ++++++++++++++++++++++++++------ src/stores/contact-item.ts | 16 +++++++++++-- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/pages/contact-edit/index.vue b/src/pages/contact-edit/index.vue index 377b485..774653d 100644 --- a/src/pages/contact-edit/index.vue +++ b/src/pages/contact-edit/index.vue @@ -12,6 +12,7 @@ const contact = useContactItemStore() const contacts = useContactsStore() contact.setContact(contactData) const showDeleteConfirmMenu = ref(false) +const showBlockConfirmMenu = ref(false) const goBack = () => { Router.back() @@ -50,7 +51,31 @@ const onSaveClicked = () => { } const onDeleteVisitor = () => { showDeleteConfirmMenu.value = true - // +} + +const onBlockVisitor = () => { + showBlockConfirmMenu.value = true +} +const onBlockConfirm = (item) => { + console.log(item) + Taro.showLoading({ + title: 'loading', + }) + + contact.setBlockStatus(!contactData.isBlock).then(r => { + contacts.loadContactsFromServer().then( contactsResult => { + contactData.isBlock = !contactData.isBlock + Taro.hideLoading() + }) + }).catch(error => { + Taro.hideLoading() + Taro.showToast({ + title: '网络异常,请稍候重试', + icon: 'none', + duration: 2000 + }) + console.log("error", error) + }) } const onDeleteConfirm = (item) => { console.log(item) @@ -73,6 +98,7 @@ const onDeleteConfirm = (item) => { console.log("error", error) }) } + diff --git a/src/stores/contact-item.ts b/src/stores/contact-item.ts index dc52f43..044dd59 100644 --- a/src/stores/contact-item.ts +++ b/src/stores/contact-item.ts @@ -70,6 +70,15 @@ export const useContactItemStore = defineStore('contact-item', () => { } ` + const CHANGE_BLOCK_STATUS = gql` + mutation UpdateVisitor($id: Long!, $isBlock: Boolean ) { + updateVisitor( input: { + id: $id, + isBlock: $isBlock + } ) + } + ` + function createVisitor() { const name = contact.value.name const nickName = contact.value.nickName @@ -128,8 +137,11 @@ export const useContactItemStore = defineStore('contact-item', () => { .catch(e=> reject(e)) } }) + } - + function setBlockStatus(isBlock: Boolean) { + const id = contact.value.id + return GQLRequest.query(CHANGE_BLOCK_STATUS, { id, isBlock }) } function deleteVisitor() { @@ -161,5 +173,5 @@ export const useContactItemStore = defineStore('contact-item', () => { } - return { contact, setContact, createVisitor, updateVisitor, deleteVisitor, getEmptyContactData, setNewAvatar} + return { contact, setContact, createVisitor, updateVisitor, deleteVisitor, getEmptyContactData, setNewAvatar, setBlockStatus } })