diff --git a/src/components/Auth.vue b/src/components/Auth.vue
deleted file mode 100644
index 1ba59c7..0000000
--- a/src/components/Auth.vue
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
diff --git a/src/components/contact-form/index.vue b/src/components/contact-form/index.vue
index 4a25a99..3aef93a 100644
--- a/src/components/contact-form/index.vue
+++ b/src/components/contact-form/index.vue
@@ -5,22 +5,24 @@ import { Router } from 'tarojs-router-next'
import { reactive, ref } from 'vue';
+import {BjxHelper} from "../../utils";
+import {useContactsStore} from "../../stores/contacts";
const props = defineProps(['data'])
-// const isSuggestionsShow = ref(false)
+const contacts = useContactsStore()
const state = reactive({
- isSuggestionsShow: false,
- name: props.data ? props.data.name : '',
- company: props.data ? props.data.company : '',
- avatar: props.data ? props.data.avatar : '',
+ isNickNameSuggestionsShow: false,
+ contactData: props.data ? props.data : contacts.getEmptyContactData(),
+ newAvatar: '',
number: '',
- isFlexVisit: props.data ? props.data.isFlexVisit : true,
+ // lastName: BjxHelper.getBJXFirstChar(name),
date: '',
isDateSelectorVisible: false
});
+
const openSwitch = (param) => {
state[`${param}`] = true;
};
@@ -32,7 +34,7 @@ const setChooseValue = (param) => {
};
function setShowSuggestions(isShow: Boolean) {
- state.isSuggestionsShow = isShow
+ state.isNickNameSuggestionsShow = isShow
}
const updateFacePhoto = () => {
@@ -41,12 +43,19 @@ const updateFacePhoto = () => {
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
- state.avatar = res.tempFilePaths
- console.log(state.avatar)
+ state.newAvatar = res.tempFilePaths
+ console.log(state.newAvatar)
},
})
}
-
+const updateNickName = (value) => {
+ if (value === null) {
+ state.isNickNameSuggestionsShow = false
+ }
+ else {
+ state.contactData.nickName = BjxHelper.getBJXFirstChar(state.contactData.name) + value;
+ }
+}
@@ -56,52 +65,59 @@ const updateFacePhoto = () => {
-
+
- {{state.avatar?'更换':'添加'}}面部识别照片
+ {{state.contactData.avatar || state.newAvatar ?'更换':'添加'}}面部识别照片
-
+
-
+
-
- 先生
- 女士
- 小姐
- 您可以从列表中选择或直接填写
+
+ {{BjxHelper.getBJXFirstChar(state.contactData.name)}}先生
+ {{BjxHelper.getBJXFirstChar(state.contactData.name)}}女士
+ {{BjxHelper.getBJXFirstChar(state.contactData.name)}}小姐
+
+
+
+ 您可以从列表中选择或直接填写
+
+ 关闭
+
+
-
+
-
+
-
+
-
+
-
+
diff --git a/src/components/contact/index.vue b/src/components/contact/index.vue
index 6f8f72b..53553ef 100644
--- a/src/components/contact/index.vue
+++ b/src/components/contact/index.vue
@@ -4,11 +4,12 @@ import { Router } from 'tarojs-router-next'
import {BjxHelper, ScreenHelper} from "../../utils";
import "./index.scss";
import {ref} from "vue";
+import {ContactData} from "../../stores/contacts";
const props = defineProps(['items'])
// const elevatorHeight = ref(ScreenHelper.getScreenHeight() - ScreenHelper.getStatusBarHeight() - ScreenHelper.getWindowBarHeight())
-const clickItem = (key: string, item: any) => {
+const clickItem = (key: string, item: ContactData) => {
console.log(key);
console.log(item.name);
@@ -28,8 +29,9 @@ const clickItem = (key: string, item: any) => {
-
- {{BjxHelper.getBJXFirstChar(item.name)}}
+
+
+ {{BjxHelper.getBJXFirstChar(item.name)}}
diff --git a/src/pages/contact/index.scss b/src/pages/contact/index.scss
index 34e6b03..2741512 100644
--- a/src/pages/contact/index.scss
+++ b/src/pages/contact/index.scss
@@ -10,3 +10,8 @@ page {
flex: 1;
overflow: scroll;
}
+
+.skeleton {
+ flex: 1;
+ overflow: hidden;
+}
diff --git a/src/pages/contact/index.vue b/src/pages/contact/index.vue
index 7f11d6e..bd750df 100644
--- a/src/pages/contact/index.vue
+++ b/src/pages/contact/index.vue
@@ -3,89 +3,53 @@ import Contact from "../../components/contact"
import { Router } from 'tarojs-router-next'
import {reactive, ref} from 'vue';
import './index.scss'
+import { useContactsStore, ContactData } from '../../stores/contacts'
+
+
import {gql} from "graphql-tag";
-import {PinyinHelper, GQLRequest} from "../../utils";
-
-interface ContactData {
- id: number
- name: string
- isVIP: boolean
- flexVisit: boolean
- isBlock: boolean
- nickName: string
- avatar: string
- phone: string
- company: string
- nextVisitDate?: string
- firstCharPinyin: string
-}
+import {PinyinHelper, GQLRequest, weappAuth} from "../../utils";
+import {useAuthStore} from "../../stores/auth";
+
+// defineExpose({
+// loadContactsFromServer,
+// });
const state = reactive<{
isContactDataLoading: boolean;
searchQuery: string;
- contactFullList: ContactData[]; // Using the ContactData interface
- contactList: ContactData[]; // Generic type for now
contactGroupedList: any[]; // Generic type for now
}>({
isContactDataLoading: true,
searchQuery: "",
- contactFullList: [],
- contactList: [],
contactGroupedList: [],
})
+const contacts = useContactsStore()
-const val = ref('');
-
-const GQL_QUERY_ALL_CONTACT = gql`
- query {
- visitors {
- id
- name
- nickname
- type
- visitorCompany
- avatar
- phone
- }
- }
- `
-
-GQLRequest.query(GQL_QUERY_ALL_CONTACT, {})
- .then( result => {
- // console.log(result)
- for(let item of result.data.visitors) {
- state.contactFullList.push({
- id: item.id,
- name: item.name,
- nickName: item.nickname,
- avatar: item.avatar,
- company: item.visitorCompany,
- phone: item.phone,
- flexVisit: "",
- isBlock: "",
- isVIP: "",
- firstCharPinyin: PinyinHelper.getPinyinGroupName(item.name)
- } as ContactData)
- }
- console.log(state.contactFullList)
- state.isContactDataLoading = false
- state.contactList = state.contactFullList
- generateContactGroupList()
- })
+
+asyncInit()
+
+async function asyncInit() {
+ state.isContactDataLoading = true
+ weappAuth()
+ .then(r => {
+ contacts.loadContactsFromServer().then(
+ contactList => {
+ console.log("contactList", contactList)
+ generateContactGroupList(contactList)
+ state.isContactDataLoading = false
+ })
+ })
+}
const onSearchValueChange = (value) => {
- state.contactList = []
- for(const item of state.contactFullList) {
- if (item.name.match(value)) {
- state.contactList.push(item)
- }
- }
- generateContactGroupList()
- console.log(state.contactList)
+ let contactList = contacts.searchContacts(value)
+ generateContactGroupList(contactList)
+ // console.log(state.contactGroupedList)
}
-const generateContactGroupList = () => {
+
+const generateContactGroupList = (contactList: ContactData[]) => {
let contactGroupedList = []
- for (const item of state.contactList) {
+ for (const item of contactList) {
const firstChar = item.firstCharPinyin;
if (!contactGroupedList[firstChar]) {
contactGroupedList[firstChar] = { title: firstChar, list: [] };
@@ -125,9 +89,7 @@ const generateContactGroupList = () => {
-
-
-
+
diff --git a/src/pages/index/index.scss b/src/pages/index/index.scss
index 1251ddd..ab1f759 100644
--- a/src/pages/index/index.scss
+++ b/src/pages/index/index.scss
@@ -11,4 +11,8 @@ page {
overflow: scroll;
}
+.skeleton {
+ flex: 1;
+ overflow: hidden;
+}
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index c4c94c3..3ba7107 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -4,15 +4,24 @@ import { View, Text } from '@tarojs/components'
import './index.scss'
import Counter from '../../components/Counter.vue'
-import Auth from "../../components/Auth"
import { ref } from 'vue'
import {useDidShow, useLoad} from "@tarojs/taro";
import { Date } from '@nutui/icons-vue-taro';
import Notification from "../../components/notification";
+import {weappAuth} from "../../utils";
+const state = reactive<{
+ isPageDataLoading: boolean,
+}>({
+ isPageDataLoading: true,
+})
+asyncInit()
-
+async function asyncInit() {
+ await weappAuth()
+ state.isPageDataLoading = false
+}
//
//
// const show = ref(false);
@@ -43,7 +52,6 @@ import Notification from "../../components/notification";
-
@@ -60,7 +68,7 @@ import Notification from "../../components/notification";
-
+
@@ -87,6 +95,9 @@ import Notification from "../../components/notification";
+
+
+
diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue
index 5469b05..45420ab 100644
--- a/src/pages/login/index.vue
+++ b/src/pages/login/index.vue
@@ -89,7 +89,7 @@ const getPhoneNumber = (e) => {
服务器错误,请稍后重试
- 您还不是数字人产品中注册的企业员工,请联系您的公司管理员开通,或与缔智元联系。
+ 您还不是数字人产品中注册的企业员工,请联系您的公司管理员开通,或与缔智元联系。
diff --git a/src/pages/settings/index.vue b/src/pages/settings/index.vue
index 06da3a4..01a06a3 100644
--- a/src/pages/settings/index.vue
+++ b/src/pages/settings/index.vue
@@ -39,7 +39,7 @@ const onExitLoginButtonClicked = () => {
}
const onAboutUsClicked = () => {
- Route.navigateTo({url: '/pages/web-view/index'}, {data: {href: "https://www.digimeta.com.cn/"}})
+ Route.navigateTo({url: '/pages/web-view/index'}, {data: {href: "https://www.digimeta.com.cn/contact"}})
console.log("onAboutUsClicked")
}
diff --git a/src/stores/contacts.ts b/src/stores/contacts.ts
new file mode 100644
index 0000000..4081e4c
--- /dev/null
+++ b/src/stores/contacts.ts
@@ -0,0 +1,113 @@
+// https://pinia.esm.dev/introduction.html
+import { defineStore } from 'pinia'
+import {GQLRequest, PinyinHelper, Session} from "../utils";
+import Taro from "@tarojs/taro";
+import {gql} from "graphql-tag";
+import {Ref, ref, UnwrapRef} from "vue";
+import {rejects} from "assert";
+
+export interface ContactData {
+ id?: number
+ name: string
+ isVIP: boolean
+ flexVisit: boolean
+ isBlock: boolean
+ nickName: string
+ avatar: string
+ phone: string
+ company: string
+ nextVisitDate?: string
+ firstCharPinyin: string
+}
+
+export const useContactsStore = defineStore('contacts', () => {
+
+ const isContactsLoaded: Ref> = ref(false)
+ const allContacts: Ref> = ref([])
+
+ const GQL_QUERY_ALL_CONTACT = gql`
+ query {
+ visitors {
+ id
+ name
+ nickname
+ type
+ visitorCompany
+ avatar
+ phone
+ }
+ }
+ `
+
+ function loadContactsFromServer () {
+ return new Promise((resolve, reject) => {
+ isContactsLoaded.value = false
+ const items: ContactData[] = []
+ return GQLRequest.query(GQL_QUERY_ALL_CONTACT, {})
+ .then(result => {
+ if (result.code == 500) {
+ reject("Network Error")
+ } else {
+ // console.log(result)
+ for (let item of result.data.visitors) {
+ items.push({
+ id: item.id,
+ name: item.name,
+ nickName: item.nickname,
+ avatar: item.avatar,
+ company: item.visitorCompany,
+ phone: item.phone,
+ flexVisit: "",
+ isBlock: "",
+ isVIP: "",
+ firstCharPinyin: PinyinHelper.getPinyinGroupName(item.name)
+ } as ContactData)
+ }
+ allContacts.value = items.sort((a, b) => a.firstCharPinyin.localeCompare(b.firstCharPinyin));
+
+ console.log(allContacts.value)
+ isContactsLoaded.value = true
+ resolve(allContacts.value)
+ }
+ })
+ })
+ }
+
+ function searchContacts(searchQuery: string) {
+ const searchedContacts: ContactData[] = []
+ for(const item of allContacts.value) {
+ if (item.name.match(searchQuery)) {
+ searchedContacts.push(item)
+ }
+ }
+ 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}
+})
+
+// You can even use a function (similar to a component setup()) to define a Store for more advanced use cases:
+// export const useCounterStore = defineStore('counter', () => {
+// const count = ref(0)
+//
+// function increment() {
+// count.value++
+// }
+//
+// return {count, increment}
+// })
diff --git a/src/utils/index.ts b/src/utils/index.ts
index fe03649..2382a5f 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -5,3 +5,4 @@ export { Route } from './route';
export { ScreenHelper } from './screen-helper';
export { Session } from './session'
export { PinyinHelper } from './pinyin-helper'
+export { weappAuth } from './weapp-auth'
diff --git a/src/utils/weapp-auth.ts b/src/utils/weapp-auth.ts
new file mode 100644
index 0000000..5f488b3
--- /dev/null
+++ b/src/utils/weapp-auth.ts
@@ -0,0 +1,54 @@
+import {useAuthStore} from "../stores/auth";
+import {Session} from "./session";
+import Taro from "@tarojs/taro";
+import {NavigateType, Router} from "tarojs-router-next";
+
+export async function weappAuth () {
+ return new Promise((resolve, reject) => {
+ const auth = useAuthStore()
+ if (Session.has('expires_in_timestamp')
+ && Session.get('expires_in_timestamp') >= new Date().getTime() + 60 * 60 * 1000) {
+ auth.isLoggedIn = true;
+ console.log(Session.all())
+ resolve()
+ } else {
+ console.log(SERVER_URL + '/system/api/weapp/login')
+ return Taro.login({
+ success: function (res) {
+ Taro.request({
+ url: SERVER_URL + '/system/api/weapp/login',
+ data: {code: res.code},
+ success: result => {
+ if (result.data.code != 200) {
+ reject(result)
+ } else {
+ for (const [key, value] of Object.entries(result.data.data)) {
+ Session.set(key, value);
+ if (key === 'expires_in') {
+ Session.set('expires_in_timestamp', new Date().getTime() + (value * 60 * 1000))
+ }
+ }
+ console.log(Session.all())
+ auth.isLoggedIn = true
+ resolve(result.data)
+ if (!Session.has('access_token')) {
+ if (Taro.getCurrentPages().length > 0) {
+ Router.navigate({url: '/pages/login/index'}, {
+ data: {prevPage: "/" + Taro.getCurrentPages()[0].route},
+ type: NavigateType.reLaunch
+ })
+ } else {
+ Router.navigate({url: '/pages/login/index'}, {type: NavigateType.reLaunch})
+ }
+ }
+ }},
+ fail: res => reject(res)
+ })
+ },
+ fail: function (res) {
+ console.log(res)
+ }
+ })
+ }
+ })
+}