Commit 02bce3e2 authored by chenqikuai's avatar chenqikuai

fix: 后端接口更新,前端修复bug

parent b5810170
import { iContact2 } from '@/service/UserService/types' import { iContact2 } from "@/service/UserService/types";
import { MyAppDatabase } from './index' import { MyAppDatabase } from "./index";
export default class ContactPersonService { export default class ContactPersonService {
static instance: ContactPersonService static instance: ContactPersonService;
private contactPerson: Dexie.Table<iContact2, number> private contactPerson: Dexie.Table<iContact2, string>;
static getInstance() { static getInstance() {
if (!ContactPersonService.instance) { if (!ContactPersonService.instance) {
ContactPersonService.instance = new ContactPersonService() ContactPersonService.instance = new ContactPersonService();
} }
return ContactPersonService.instance return ContactPersonService.instance;
} }
constructor() { constructor() {
const db = new MyAppDatabase() const db = new MyAppDatabase();
this.contactPerson = db.contactPerson this.contactPerson = db.contactPerson;
} }
save(list: iContact2[]) { save(list: iContact2[]) {
return this.contactPerson.bulkAdd(list) return this.contactPerson.bulkPut(list);
} }
async findByList(addressList: string[]) { async findByList(addressList: string[]) {
const list = await this.contactPerson const list = await this.contactPerson
.filter((i) => { .filter((i) => {
return addressList.includes(i.addr) return addressList.includes(i.addr);
}) })
.toArray() .toArray();
const notFoundList = addressList.filter( const notFoundList = addressList.filter(
(i) => list.findIndex((item) => item?.addr === i) === -1, (i) => list.findIndex((item) => item?.addr === i) === -1
) );
return { return {
foundList: list, foundList: list,
notFoundList, notFoundList,
} };
} }
} }
...@@ -15,7 +15,7 @@ export default class OutletDBService { ...@@ -15,7 +15,7 @@ export default class OutletDBService {
} }
add(outlet: iOutLet) { add(outlet: iOutLet) {
return this.outlet.add(outlet); return this.outlet.put(outlet);
} }
update(outlet: Partial<Omit<iOutLet, "id">> & Pick<iOutLet, "posId">) { update(outlet: Partial<Omit<iOutLet, "id">> & Pick<iOutLet, "posId">) {
......
...@@ -26,19 +26,19 @@ export interface iOutLet { ...@@ -26,19 +26,19 @@ export interface iOutLet {
export class MyAppDatabase extends Dexie { export class MyAppDatabase extends Dexie {
chatMessage: Dexie.Table<iChatMessage, number>; chatMessage: Dexie.Table<iChatMessage, number>;
chatListCard: Dexie.Table<iChatListCard, number>; chatListCard: Dexie.Table<iChatListCard, number>;
contactPerson: Dexie.Table<iContact2, number>; contactPerson: Dexie.Table<iContact2, string>;
userInfo: Dexie.Table<iUserinfo, number>; userInfo: Dexie.Table<iUserinfo, number>;
outlet: Dexie.Table<iOutLet, string>; outlet: Dexie.Table<iOutLet, string>;
constructor() { constructor() {
super("MyAppDatabase"); super("MyAppDatabase");
this.version(1.7).stores({ this.version(1.8).stores({
chatMessage: chatMessage:
"++id, content, from, uuid, state, uploadProgress, type, datetime, hideDatetime, logid, masterId, readed", "++id, content, from, uuid, state, uploadProgress, type, datetime, hideDatetime, logid, masterId, readed",
chatListCard: chatListCard:
"++id, masterId, targetId, unreadMsgCount, content, inChat, isRobootCard,isDeleted", "++id, masterId, targetId, unreadMsgCount, content, inChat, isRobootCard,isDeleted",
contactPerson: "++id, addr, bank, phone, user_name, out_let_name", contactPerson: "addr, bank, phone, user_name, out_let_name",
userInfo: "++id, created_at, phone, remark, user_name, uuid, addr", userInfo: "++id, created_at, phone, remark, user_name, uuid, addr",
outlet: "posId, name, isDeleted", outlet: "posId, name, isDeleted",
}); });
......
...@@ -9,7 +9,8 @@ import { getUserMsg } from "./userMsg"; ...@@ -9,7 +9,8 @@ import { getUserMsg } from "./userMsg";
/* 拿到地址对应的用户昵称 */ /* 拿到地址对应的用户昵称 */
export const getDisplayNamesFromAddress = async ( export const getDisplayNamesFromAddress = async (
addressList: string[] addressList: string[],
forceFetch?: boolean
): Promise<string[]> => { ): Promise<string[]> => {
/* 数据库查 有结果拿 没结果网上查且存 */ /* 数据库查 有结果拿 没结果网上查且存 */
const user = getUserMsg(); const user = getUserMsg();
...@@ -17,6 +18,9 @@ export const getDisplayNamesFromAddress = async ( ...@@ -17,6 +18,9 @@ export const getDisplayNamesFromAddress = async (
let foundList = [] as any[]; let foundList = [] as any[];
let notFoundList = [] as any[]; let notFoundList = [] as any[];
if (forceFetch) {
notFoundList = addressList;
} else {
if (user?.role2 === eRole.user) { if (user?.role2 === eRole.user) {
const ret = await ContactPersonService.getInstance().findByList( const ret = await ContactPersonService.getInstance().findByList(
addressList addressList
...@@ -28,6 +32,7 @@ export const getDisplayNamesFromAddress = async ( ...@@ -28,6 +32,7 @@ export const getDisplayNamesFromAddress = async (
foundList = ret.foundList; foundList = ret.foundList;
notFoundList = ret.notFoundList; notFoundList = ret.notFoundList;
} }
}
const fullList = foundList as unknown as any; const fullList = foundList as unknown as any;
...@@ -64,11 +69,14 @@ export const getDisplayNamesFromAddress = async ( ...@@ -64,11 +69,14 @@ export const getDisplayNamesFromAddress = async (
}; };
/* 获取网点名称 indexeddb数据库查,没有,则发起请求查*/ /* 获取网点名称 indexeddb数据库查,没有,则发起请求查*/
export const getDisplayNamesFromOutletId = async (outletPosId: string[]) => { export const getDisplayNamesFromOutletId = async (
outletPosId: string[],
forceFetch?: boolean
) => {
const promiseList = outletPosId.map(async (id) => { const promiseList = outletPosId.map(async (id) => {
const outlet = await OutletDBService.getInstance().get(id); const outlet = await OutletDBService.getInstance().get(id);
if (!outlet) { if (forceFetch || !outlet) {
const ret = await AddressService.getInstance().getOutlet({ const ret = await AddressService.getInstance().getOutlet({
pos_id: id, pos_id: id,
}); });
...@@ -88,13 +96,18 @@ export const getDisplayNamesFromOutletId = async (outletPosId: string[]) => { ...@@ -88,13 +96,18 @@ export const getDisplayNamesFromOutletId = async (outletPosId: string[]) => {
}; };
export const getDisplayNames = async ( export const getDisplayNames = async (
list: { outletPosId?: string; address?: string }[] list: { outletPosId?: string; address?: string }[],
forceFetch?: boolean
) => { ) => {
const promiseList = list.map((i) => { const promiseList = list.map((i) => {
if (i.outletPosId !== undefined) { if (i.outletPosId !== undefined) {
return getDisplayNamesFromOutletId([i.outletPosId]).then((ret) => ret[0]); return getDisplayNamesFromOutletId([i.outletPosId], forceFetch).then(
(ret) => ret[0]
);
} else if (i.address !== undefined) { } else if (i.address !== undefined) {
return getDisplayNamesFromAddress([i.address]).then((ret) => ret[0]); return getDisplayNamesFromAddress([i.address], forceFetch).then(
(ret) => ret[0]
);
} else return ""; } else return "";
}); });
......
...@@ -310,15 +310,25 @@ export default defineComponent({ ...@@ -310,15 +310,25 @@ export default defineComponent({
const initTitle = async () => { const initTitle = async () => {
if (isChatWithRoboot.value) { if (isChatWithRoboot.value) {
const list = await getDisplayNames([ let list = await getDisplayNames([
{ outletPosId: route.query.targetId as string }, { outletPosId: route.query.targetId as string },
]); ]);
title.value = list[0] as string; title.value = list[0] as string;
list = await getDisplayNames(
[{ outletPosId: route.query.targetId as string }],
true
);
title.value = list[0] as string;
} else { } else {
const list = await getDisplayNames([ let list = await getDisplayNames([
{ address: route.query.targetId as string }, { address: route.query.targetId as string },
]); ]);
title.value = list[0] as string; title.value = list[0] as string;
list = await getDisplayNames(
[{ address: route.query.targetId as string }],
true
);
title.value = list[0] as string;
} }
}; };
......
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
<Skeleton :loading="state.loading" :row="4"> <Skeleton :loading="state.loading" :row="4">
<branch <branch
class="mt-3 mx-5" class="mt-3 mx-5"
v-if="state.branchinfo || !isUser" v-if="state.branchinfo.pos_id || !isUser"
:name="state.branchinfo.name" :name="state.branchinfo.name"
:distance="state.branchinfo.distance" :distance="state.branchinfo.distance"
:is_normal_work="state.branchinfo.is_normal_work" :is_normal_work="state.branchinfo.is_normal_work"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment