diff --git a/components.d.ts b/components.d.ts index 2ade2b7..ed83fe3 100644 --- a/components.d.ts +++ b/components.d.ts @@ -7,7 +7,6 @@ export {} declare module 'vue' { export interface GlobalComponents { - Auth: typeof import('./src/components/Auth.vue')['default'] BackgroundBasic: typeof import('./src/components/background-basic/index.vue')['default'] Contact: typeof import('./src/components/contact/index.vue')['default'] ContactForm: typeof import('./src/components/contact-form/index.vue')['default'] @@ -23,6 +22,7 @@ declare module 'vue' { NutCollapseItem: typeof import('@nutui/nutui-taro')['CollapseItem'] NutDivider: typeof import('@nutui/nutui-taro')['Divider'] NutElevator: typeof import('@nutui/nutui-taro')['Elevator'] + NutEmpty: typeof import('@nutui/nutui-taro')['Empty'] NutForm: typeof import('@nutui/nutui-taro')['Form'] NutFormItem: typeof import('@nutui/nutui-taro')['FormItem'] NutInput: typeof import('@nutui/nutui-taro')['Input'] diff --git a/src/components/contact-form/index.vue b/src/components/contact-form/index.vue index 3aef93a..c9c65ae 100644 --- a/src/components/contact-form/index.vue +++ b/src/components/contact-form/index.vue @@ -7,18 +7,16 @@ import { Router } from 'tarojs-router-next' import { reactive, ref } from 'vue'; import {BjxHelper} from "../../utils"; import {useContactsStore} from "../../stores/contacts"; +import {useContactItemStore} from "../../stores/contact-item"; const props = defineProps(['data']) const contacts = useContactsStore() +const contact = useContactItemStore() const state = reactive({ isNickNameSuggestionsShow: false, - contactData: props.data ? props.data : contacts.getEmptyContactData(), newAvatar: '', - number: '', - // lastName: BjxHelper.getBJXFirstChar(name), - date: '', isDateSelectorVisible: false }); @@ -29,8 +27,8 @@ const openSwitch = (param) => { const closeSwitch = (param) => { state[`${param}`] = false; }; -const setChooseValue = (param) => { - state.date = param[3]; +const setChooseDate = (param) => { + contact.contact.nextVisitDate = param[3] }; function setShowSuggestions(isShow: Boolean) { @@ -53,7 +51,7 @@ const updateNickName = (value) => { state.isNickNameSuggestionsShow = false } else { - state.contactData.nickName = BjxHelper.getBJXFirstChar(state.contactData.name) + value; + contact.contact.nickName = BjxHelper.getBJXFirstChar(contact.contact.name) + value; } } @@ -65,27 +63,27 @@ const updateNickName = (value) => { - + - {{state.contactData.avatar || state.newAvatar ?'更换':'添加'}}面部识别照片 + {{contact.contact.avatar || state.newAvatar ?'更换':'添加'}}面部识别照片 - + - + - {{BjxHelper.getBJXFirstChar(state.contactData.name)}}先生 - {{BjxHelper.getBJXFirstChar(state.contactData.name)}}女士 - {{BjxHelper.getBJXFirstChar(state.contactData.name)}}小姐 + {{BjxHelper.getBJXFirstChar(contact.contact.name)}}先生 + {{BjxHelper.getBJXFirstChar(contact.contact.name)}}女士 + {{BjxHelper.getBJXFirstChar(contact.contact.name)}}小姐 @@ -97,31 +95,31 @@ const updateNickName = (value) => { - + - + - + - + - + - {{state.date ? state.date : '请选择'}} + {{contact.contact.nextVisitDate ? contact.contact.nextVisitDate : '请选择'}} @@ -131,8 +129,8 @@ const updateNickName = (value) => { diff --git a/src/components/contact/index.vue b/src/components/contact/index.vue index 53553ef..3258539 100644 --- a/src/components/contact/index.vue +++ b/src/components/contact/index.vue @@ -10,8 +10,8 @@ const props = defineProps(['items']) // const elevatorHeight = ref(ScreenHelper.getScreenHeight() - ScreenHelper.getStatusBarHeight() - ScreenHelper.getWindowBarHeight()) const clickItem = (key: string, item: ContactData) => { - console.log(key); - console.log(item.name); + console.log(key, item.name); + console.log(item); Router.toContactEdit({ data: item }) } diff --git a/src/pages/contact-edit/index.vue b/src/pages/contact-edit/index.vue index 8a5f2b0..85545b8 100644 --- a/src/pages/contact-edit/index.vue +++ b/src/pages/contact-edit/index.vue @@ -1,14 +1,41 @@ diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 3ba7107..a9761ac 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -12,15 +12,29 @@ import {weappAuth} from "../../utils"; const state = reactive<{ isPageDataLoading: boolean, + isAuthError: boolean, }>({ isPageDataLoading: true, + isAuthError: false }) -asyncInit() +init() + +function init() { + state.isAuthError = false + state.isPageDataLoading = true + weappAuth().then(r => { + console.log(r) + state.isPageDataLoading = false + }).catch(e => { + console.log("error", e) + state.isAuthError = true + state.isPageDataLoading = false + }) +} -async function asyncInit() { - await weappAuth() - state.isPageDataLoading = false +const onAuthErrorRefresh = () => { + init() } // // @@ -68,35 +82,44 @@ async function asyncInit() { - - - - - - - - - - - - - - - - - - - - - 没有更多了 + + +
+ 刷新 +
+
+
+ + + + + + + + + + + + + + + + + + + + + + 没有更多了 + + - - - - - - +
+
+ + +
diff --git a/src/stores/contact-item.ts b/src/stores/contact-item.ts new file mode 100644 index 0000000..7439edb --- /dev/null +++ b/src/stores/contact-item.ts @@ -0,0 +1,90 @@ +// https://pinia.esm.dev/introduction.html +import { defineStore } from 'pinia' +import {GQLRequest} from "../utils"; +import {gql} from "graphql-tag"; +import {ContactData} from "./contacts"; +import {ref, Ref, UnwrapRef} from "vue"; + +export const useContactItemStore = defineStore('contact-item', () => { + + const contact: Ref> = ref(getEmptyContactData()) + + function setContact(contactItem: ContactData) { + contact.value = contactItem + console.log("setContact", contact.value) + } + + function getEmptyContactData(): ContactData { + return { + id: undefined, + name: "", + isVIP: false, + flexVisit: false, + isBlock: false, + nickName: "", + avatar: "", + phone: "", + company: "", + nextVisitDate: undefined, + firstCharPinyin: "" + } + } + + const CREATE_VISITOR = gql` + mutation CreateVisitor($name: String!, $nickName: String, $phone: String, $company: String, $isVIP: Boolean, $flexVisit: Boolean, $resourceId: Long ) { + createVisitor( input: { + name: $name, + nickname: $nickName, + phone: $phone, + visitorCompany: $company, + isVip: $isVIP, + flexVisit: $flexVisit, + resourceId: $resourceId + } ) { + result + } + } + ` + + const UPDATE_VISITOR = gql` + mutation UpdateVisitor($id: Long!, $name: String!, $nickName: String, $phone: String, $company: String, $isVIP: Boolean, $flexVisit: Boolean, $resourceId: Long ) { + updateVisitor( input: { + id: $id, + name: $name, + nickname: $nickName, + phone: $phone, + visitorCompany: $company, + isVip: $isVIP, + flexVisit: $flexVisit, + resourceId: $resourceId + } ) + } + ` + + function createVisitor() { + const name = contact.value.name + const nickName = contact.value.nickName + const phone = contact.value.phone + const company = contact.value.company + const isVIP = contact.value.isVIP + const flexVisit = contact.value.flexVisit + + return GQLRequest.query(CREATE_VISITOR, { name, nickName, phone, company, isVIP, flexVisit }) + } + + function updateVisitor() { + const id = contact.value.id + const name = contact.value.name + const nickName = contact.value.nickName + const phone = contact.value.phone + const company = contact.value.company + const isVIP = contact.value.isVIP + const flexVisit = contact.value.flexVisit + + console.log(contact.value) + return GQLRequest.query(UPDATE_VISITOR, {id, name, nickName, phone, company, isVIP, flexVisit }) + } + + + return { contact, setContact, createVisitor, updateVisitor} +}) diff --git a/src/stores/contacts.ts b/src/stores/contacts.ts index 4081e4c..e41c8a1 100644 --- a/src/stores/contacts.ts +++ b/src/stores/contacts.ts @@ -31,10 +31,13 @@ export const useContactsStore = defineStore('contacts', () => { id name nickname + phone type visitorCompany avatar - phone + isVip + flexVisit + isBlock } } ` @@ -48,7 +51,7 @@ export const useContactsStore = defineStore('contacts', () => { if (result.code == 500) { reject("Network Error") } else { - // console.log(result) + console.log(result) for (let item of result.data.visitors) { items.push({ id: item.id, @@ -57,9 +60,9 @@ export const useContactsStore = defineStore('contacts', () => { avatar: item.avatar, company: item.visitorCompany, phone: item.phone, - flexVisit: "", - isBlock: "", - isVIP: "", + flexVisit: item.flexVisit, + isBlock: item.isBlock, + isVIP: item.isVip, firstCharPinyin: PinyinHelper.getPinyinGroupName(item.name) } as ContactData) } @@ -83,22 +86,7 @@ export const useContactsStore = defineStore('contacts', () => { return searchedContacts } - function getEmptyContactData(): ContactData { - return { - id: undefined, - name: "", - isVIP: false, - flexVisit: false, - isBlock: false, - nickName: "", - avatar: "", - phone: "", - company: "", - nextVisitDate: undefined, - firstCharPinyin: "" - } - } - return { allContacts , isContactsLoaded, loadContactsFromServer, searchContacts, getEmptyContactData} + return { allContacts , isContactsLoaded, loadContactsFromServer, searchContacts} }) // You can even use a function (similar to a component setup()) to define a Store for more advanced use cases: diff --git a/src/utils/GQLRequest.ts b/src/utils/GQLRequest.ts index cce53fb..b84b1d6 100644 --- a/src/utils/GQLRequest.ts +++ b/src/utils/GQLRequest.ts @@ -13,7 +13,8 @@ export class GQLRequest { }, data: JSON.stringify({ query: print(documentNode), variables: variable }), success: result => { - if (result.statusCode == 200) resolve(result.data) + if ((result.data as any).hasOwnProperty("errors")) reject(result) + else if (result.statusCode == 200) resolve(result.data) else reject(result) }, fail: res => reject(res)