Commit 02bce3e2 authored by chenqikuai's avatar chenqikuai

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

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