This commit is contained in:
wangwenchen 2023-10-10 15:49:52 +08:00
parent a8aad2a51a
commit ae09b099b7
13 changed files with 243 additions and 141 deletions

View File

@ -82,7 +82,8 @@ export async function createSession(params, context) {
} }
case 'wechatMp': case 'wechatMp':
case 'wechatPublic': { case 'wechatPublic': {
assert(data, ''); assert(data);
assert(entity === 'application');
const { ToUserName, FromUserName, CreateTime, MsgType, const { ToUserName, FromUserName, CreateTime, MsgType,
// Event, // Event,
Content, Content,
@ -98,6 +99,22 @@ export async function createSession(params, context) {
openId: FromUserName, openId: FromUserName,
} }
}, {}); }, {});
const result = await context.select('session', {
data: {
id: 1,
entity: 1,
entityId: 1,
userId: 1,
lmts: 1,
openId: 1,
},
filter: {
entity: entity,
entityId: entityId,
openId: FromUserName,
}
}, {});
session = result[0];
sessionMessage$session = [ sessionMessage$session = [
{ {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
@ -105,8 +122,7 @@ export async function createSession(params, context) {
data: { data: {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
applicationId: wechatUser?.applicationId, applicationId: wechatUser?.applicationId,
// sessionId: session[0]?.id, wechatUserId: wechatUser?.id,
wechatUser: wechatUser?.id,
createTime: CreateTime, createTime: CreateTime,
type: MsgType, type: MsgType,
text: Content, text: Content,
@ -148,6 +164,7 @@ export async function createSession(params, context) {
entityId, entityId,
userId, userId,
lmts: Date.now(), lmts: Date.now(),
openId: data?.FromUserName,
}, sessionMessage$session && { sessionMessage$session }), }, sessionMessage$session && { sessionMessage$session }),
}, { }, {
dontCollect: true, dontCollect: true,

View File

@ -6,6 +6,7 @@ export default OakComponent({
entity: 1, entity: 1,
entityId: 1, entityId: 1,
lmts: 1, lmts: 1,
openId: 1,
user: { user: {
id: 1, id: 1,
name: 1, name: 1,
@ -137,7 +138,7 @@ export default OakComponent({
} }
}, },
getName() { getName() {
const { user, entity } = this.state; const { user, entity, openId } = this.state;
const { entityFilter } = this.props; const { entityFilter } = this.props;
if (entityFilter) { if (entityFilter) {
const userName = user?.name; const userName = user?.name;
@ -150,6 +151,9 @@ export default OakComponent({
if (userMobile) { if (userMobile) {
return '用户' + userMobile; return '用户' + userMobile;
} }
if (openId) {
return '微信用户' + openId;
}
return userNickname; return userNickname;
} }
else { else {

View File

@ -6,6 +6,7 @@ export default OakComponent({
id: 1, id: 1,
entity: 1, entity: 1,
entityId: 1, entityId: 1,
openId: 1,
userId: 1, userId: 1,
user: { user: {
id: 1, id: 1,

View File

@ -258,43 +258,36 @@ export default OakComponent({
const extension = name.substring(name.lastIndexOf('.') + 1); const extension = name.substring(name.lastIndexOf('.') + 1);
const filename = name.substring(0, name.lastIndexOf('.')); const filename = name.substring(0, name.lastIndexOf('.'));
const extraFile = { const extraFile = {
extra1: originFileObj,
origin: 'qiniu', origin: 'qiniu',
type: 'image', type: 'image',
tag1: 'image', tag1: 'image',
objectId: generateNewId(),
filename, filename,
fileType: type, fileType: type,
size, size,
extension, extension,
entity: 'sessionMessage', entity: 'sessionMessage',
bucket: '',
id: generateNewId(), id: generateNewId(),
}; };
// try { try {
// // 自己实现上传,并得到图片 url alt href await this.features.extraFile.upload(extraFile, originFileObj);
// const { url, bucket } = await this.features.extraFile.upload( const userId = this.features.token.getUserId();
// extraFile this.addItem({
// ); id: generateNewId(),
// extraFile.bucket = bucket; sessionId,
// extraFile.extra1 = null; type: 'image',
// const userId = this.features.token.getUserId(); extraFile$entity: [
// this.addItem({ {
// id: generateNewId(), id: generateNewId(),
// sessionId, action: 'create',
// type: 'image', data: extraFile,
// extraFile$entity: [ },
// { ],
// id: generateNewId(), });
// action: 'create', await this.execute(undefined, false);
// data: extraFile, }
// }, catch (err) {
// ], throw err;
// } as EntityDict['sessionMessage']['CreateSingle']['data']); }
// await this.execute(undefined, false);
// } catch (err) {
// throw err;
// }
}, },
}, },
}); });

View File

@ -86,7 +86,8 @@ async function createSession(params, context) {
} }
case 'wechatMp': case 'wechatMp':
case 'wechatPublic': { case 'wechatPublic': {
(0, assert_1.default)(data, ''); (0, assert_1.default)(data);
(0, assert_1.default)(entity === 'application');
const { ToUserName, FromUserName, CreateTime, MsgType, const { ToUserName, FromUserName, CreateTime, MsgType,
// Event, // Event,
Content, Content,
@ -102,6 +103,22 @@ async function createSession(params, context) {
openId: FromUserName, openId: FromUserName,
} }
}, {}); }, {});
const result = await context.select('session', {
data: {
id: 1,
entity: 1,
entityId: 1,
userId: 1,
lmts: 1,
openId: 1,
},
filter: {
entity: entity,
entityId: entityId,
openId: FromUserName,
}
}, {});
session = result[0];
sessionMessage$session = [ sessionMessage$session = [
{ {
id: await (0, uuid_1.generateNewIdAsync)(), id: await (0, uuid_1.generateNewIdAsync)(),
@ -109,8 +126,7 @@ async function createSession(params, context) {
data: { data: {
id: await (0, uuid_1.generateNewIdAsync)(), id: await (0, uuid_1.generateNewIdAsync)(),
applicationId: wechatUser?.applicationId, applicationId: wechatUser?.applicationId,
// sessionId: session[0]?.id, wechatUserId: wechatUser?.id,
wechatUser: wechatUser?.id,
createTime: CreateTime, createTime: CreateTime,
type: MsgType, type: MsgType,
text: Content, text: Content,
@ -152,6 +168,7 @@ async function createSession(params, context) {
entityId, entityId,
userId, userId,
lmts: Date.now(), lmts: Date.now(),
openId: data?.FromUserName,
}, sessionMessage$session && { sessionMessage$session }), }, sessionMessage$session && { sessionMessage$session }),
}, { }, {
dontCollect: true, dontCollect: true,

View File

@ -8,6 +8,7 @@ exports.default = OakComponent({
entity: 1, entity: 1,
entityId: 1, entityId: 1,
lmts: 1, lmts: 1,
openId: 1,
user: { user: {
id: 1, id: 1,
name: 1, name: 1,
@ -139,7 +140,7 @@ exports.default = OakComponent({
} }
}, },
getName() { getName() {
const { user, entity } = this.state; const { user, entity, openId } = this.state;
const { entityFilter } = this.props; const { entityFilter } = this.props;
if (entityFilter) { if (entityFilter) {
const userName = user?.name; const userName = user?.name;
@ -152,6 +153,9 @@ exports.default = OakComponent({
if (userMobile) { if (userMobile) {
return '用户' + userMobile; return '用户' + userMobile;
} }
if (openId) {
return '微信用户' + openId;
}
return userNickname; return userNickname;
} }
else { else {

View File

@ -8,6 +8,7 @@ exports.default = OakComponent({
id: 1, id: 1,
entity: 1, entity: 1,
entityId: 1, entityId: 1,
openId: 1,
userId: 1, userId: 1,
user: { user: {
id: 1, id: 1,

View File

@ -260,43 +260,36 @@ exports.default = OakComponent({
const extension = name.substring(name.lastIndexOf('.') + 1); const extension = name.substring(name.lastIndexOf('.') + 1);
const filename = name.substring(0, name.lastIndexOf('.')); const filename = name.substring(0, name.lastIndexOf('.'));
const extraFile = { const extraFile = {
extra1: originFileObj,
origin: 'qiniu', origin: 'qiniu',
type: 'image', type: 'image',
tag1: 'image', tag1: 'image',
objectId: (0, uuid_1.generateNewId)(),
filename, filename,
fileType: type, fileType: type,
size, size,
extension, extension,
entity: 'sessionMessage', entity: 'sessionMessage',
bucket: '',
id: (0, uuid_1.generateNewId)(), id: (0, uuid_1.generateNewId)(),
}; };
// try { try {
// // 自己实现上传,并得到图片 url alt href await this.features.extraFile.upload(extraFile, originFileObj);
// const { url, bucket } = await this.features.extraFile.upload( const userId = this.features.token.getUserId();
// extraFile this.addItem({
// ); id: (0, uuid_1.generateNewId)(),
// extraFile.bucket = bucket; sessionId,
// extraFile.extra1 = null; type: 'image',
// const userId = this.features.token.getUserId(); extraFile$entity: [
// this.addItem({ {
// id: generateNewId(), id: (0, uuid_1.generateNewId)(),
// sessionId, action: 'create',
// type: 'image', data: extraFile,
// extraFile$entity: [ },
// { ],
// id: generateNewId(), });
// action: 'create', await this.execute(undefined, false);
// data: extraFile, }
// }, catch (err) {
// ], throw err;
// } as EntityDict['sessionMessage']['CreateSingle']['data']); }
// await this.execute(undefined, false);
// } catch (err) {
// throw err;
// }
}, },
}, },
}); });

View File

@ -102,7 +102,8 @@ export async function createSession<
} }
case 'wechatMp': case 'wechatMp':
case 'wechatPublic': { case 'wechatPublic': {
assert(data, '') assert(data);
assert(entity === 'application');
const { const {
ToUserName, ToUserName,
FromUserName, FromUserName,
@ -122,6 +123,22 @@ export async function createSession<
openId: FromUserName, openId: FromUserName,
} }
}, {}); }, {});
const result = await context.select('session', {
data: {
id: 1,
entity: 1,
entityId: 1,
userId: 1,
lmts: 1,
openId: 1,
},
filter: {
entity: entity,
entityId: entityId,
openId: FromUserName,
}
}, {});
session = result[0]
sessionMessage$session = [ sessionMessage$session = [
{ {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
@ -129,8 +146,7 @@ export async function createSession<
data: { data: {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
applicationId: wechatUser?.applicationId, applicationId: wechatUser?.applicationId,
// sessionId: session[0]?.id, wechatUserId: wechatUser?.id,
wechatUser: wechatUser?.id,
createTime: CreateTime, createTime: CreateTime,
type: MsgType, type: MsgType,
text: Content, text: Content,
@ -166,6 +182,7 @@ export async function createSession<
return session.id return session.id
} }
else { else {
await context.operate('session', { await context.operate('session', {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
action: 'create', action: 'create',
@ -175,6 +192,7 @@ export async function createSession<
entityId, entityId,
userId, userId,
lmts: Date.now(), lmts: Date.now(),
openId: data?.FromUserName,
}, sessionMessage$session && { sessionMessage$session }), }, sessionMessage$session && { sessionMessage$session }),
}, { }, {
dontCollect: true, dontCollect: true,

View File

@ -6,6 +6,7 @@ export default OakComponent({
entity: 1, entity: 1,
entityId: 1, entityId: 1,
lmts: 1, lmts: 1,
openId: 1,
user: { user: {
id: 1, id: 1,
name: 1, name: 1,
@ -149,7 +150,7 @@ export default OakComponent({
} }
}, },
getName() { getName() {
const { user, entity } = this.state; const { user, entity, openId } = this.state;
const { entityFilter } = this.props; const { entityFilter } = this.props;
if (entityFilter) { if (entityFilter) {
@ -164,6 +165,9 @@ export default OakComponent({
if (userMobile) { if (userMobile) {
return '用户' + userMobile; return '用户' + userMobile;
} }
if (openId) {
return '微信用户' + openId;
}
return userNickname; return userNickname;

View File

@ -8,6 +8,7 @@ export default OakComponent({
id: 1, id: 1,
entity: 1, entity: 1,
entityId: 1, entityId: 1,
openId: 1,
userId: 1, userId: 1,
user: { user: {
id: 1, id: 1,

View File

@ -1,6 +1,8 @@
import { EntityDict } from '../../../oak-app-domain'; import { EntityDict } from '../../../oak-app-domain';
import { generateNewId } from 'oak-domain/lib/utils/uuid'; import { generateNewId } from 'oak-domain/lib/utils/uuid';
import { DATA_SUBSCRIBER_KEYS } from '../../../config/constants' import { DATA_SUBSCRIBER_KEYS } from '../../../config/constants';
import { getConfig } from '../../../utils/getContextConfig';
import { QiniuCosConfig } from '../../../types/Config';
export default OakComponent({ export default OakComponent({
entity: 'sessionMessage', entity: 'sessionMessage',
projection: { projection: {
@ -44,6 +46,7 @@ export default OakComponent({
lifetimes: { lifetimes: {
async ready() { async ready() {
const { sessionId } = this.props; const { sessionId } = this.props;
await this.subData([ await this.subData([
{ {
entity: 'sessionMessage', entity: 'sessionMessage',
@ -55,31 +58,8 @@ export default OakComponent({
], ],
async () => { await this.pageScroll('comment') } async () => { await this.pageScroll('comment') }
) )
// const userId = this.features.token.getUserId(true);
// const applicationId = this.features.application.getApplicationId(); this.createItem();
// if (!sessionId) {
// const entity = 'application';
// const entityId = applicationId;
// const type = 'web';
// const { result: newSessionId } = await this.features.cache.exec('createSession', { type, entity, entityId });
// this.setState({
// newSessionId,
// })
// }
// if (!userId) {
// this.redirectTo(
// {
// url: '/login',
// backUrl: encodeURIComponent(window.location.href),
// },
// undefined,
// true
// );
// return;
// }
// (this as any).timer = setInterval(() => {
// this.refresh();
// }, 2000);
this.getConversationInfo(); this.getConversationInfo();
}, },
detached() { detached() {
@ -103,21 +83,33 @@ export default OakComponent({
sessionId(prev, next) { sessionId(prev, next) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
if (prev.sessionId !== next.sessionId) { if (prev.sessionId !== next.sessionId) {
if (next.sessionId) { if (next.sessionId) {
const { sessionMessageId } = this.state;
this.getConversationInfo(); this.getConversationInfo();
// 如果sessionId变了需要重新刷新下 // 如果sessionId变了需要重新刷新下
this.refresh(); this.refresh();
this.removeItem(sessionMessageId);
this.setState({
text: '',
});
this.createItem();
this.pageScroll('comment');
} }
} }
} }
}, },
}, },
formData({ data: sessionMessageList = [], features }) { formData({ data: sessionMessageList = [], features }) {
const sessionMessageType = sessionMessageList?.find(
(ele) => ele.$$createAt$$ === 1
)?.type;
return { return {
sessionMessageList, sessionMessageList,
num: sessionMessageList?.length, num: sessionMessageList?.length,
sessionMessageType,
}; };
}, },
properties: { properties: {
@ -134,9 +126,6 @@ export default OakComponent({
const { sessionId } = this.props; const { sessionId } = this.props;
return { return {
sessionId, sessionId,
// type: {
// $exists: true,
// },
}; };
}, },
}, },
@ -159,9 +148,17 @@ export default OakComponent({
}, },
methods: { methods: {
setContent(text: string) { setContent(text: string) {
const { sessionMessageId } = this.state;
console.log(sessionMessageId, text)
this.setState({ this.setState({
text, text,
}); });
this.updateItem({
text,
type: 'text',
}, sessionMessageId)
}, },
setButtonHidden(isHidden: boolean) { setButtonHidden(isHidden: boolean) {
this.setState({ this.setState({
@ -230,8 +227,25 @@ export default OakComponent({
setTimeout(() => doc.scrollTo(0, 10000), 500); setTimeout(() => doc.scrollTo(0, 10000), 500);
}, },
async createItem() {
const { text, wechatUserId } = this.state;
const { sessionId, isEntity } = this.props;
const userId = this.features.token.getUserId();
const applicationId = this.features.application.getApplicationId();
const sessionMessageId = this.addItem({
applicationId,
userId,
wechatUserId,
sessionId: sessionId,
aaoe: isEntity,
})
this.setState({
sessionMessageId,
})
},
async createMessage() { async createMessage() {
const { text, wechatUserId, newSessionId } = this.state; const { text, wechatUserId, newSessionId, sessionMessageId } = this.state;
const { sessionId, isEntity } = this.props; const { sessionId, isEntity } = this.props;
const userId = this.features.token.getUserId(); const userId = this.features.token.getUserId();
const applicationId = this.features.application.getApplicationId(); const applicationId = this.features.application.getApplicationId();
@ -242,21 +256,25 @@ export default OakComponent({
}); });
return; return;
} }
this.addItem({ // this.addItem({
applicationId, // applicationId,
text, // text,
userId, // userId,
wechatUserId, // wechatUserId,
sessionId: sessionId || newSessionId, // sessionId: sessionId || newSessionId,
type: 'text', // type: 'text',
// createTime: Date.now(),
// aaoe: isEntity,
// } as EntityDict['sessionMessage']['CreateSingle']['data']);
this.updateItem({
createTime: Date.now(), createTime: Date.now(),
aaoe: isEntity, }, sessionMessageId)
} as EntityDict['sessionMessage']['CreateSingle']['data']);
await this.execute(undefined, false); await this.execute(undefined, false);
this.setState({ this.setState({
text: '', text: '',
}); });
this.pageScroll('comment'); this.pageScroll('comment');
this.createItem();
}, },
@ -266,53 +284,64 @@ export default OakComponent({
type: string; type: string;
originFileObj: File; originFileObj: File;
}) { }) {
const { sessionId } = this.props; const { sessionId, isEntity } = this.props;
// TS 语法 // TS 语法
// file 即选中的文件 // file 即选中的文件
const { name, size, type, originFileObj } = file; const { name, size, type, originFileObj } = file;
const applicationId = this.features.application.getApplicationId();
const extension = name.substring(name.lastIndexOf('.') + 1); const extension = name.substring(name.lastIndexOf('.') + 1);
const filename = name.substring(0, name.lastIndexOf('.')); const filename = name.substring(0, name.lastIndexOf('.'));
let bucket2 = '';
if (!bucket2) {
const context = this.features.cache.begin();
const { config } = getConfig(context, 'Cos', 'qiniu');
this.features.cache.commit();
const { defaultBucket } = config as QiniuCosConfig;
bucket2 = defaultBucket!;
}
const extraFile = { const extraFile = {
extra1: originFileObj as any, applicationId,
bucket: bucket2,
origin: 'qiniu', origin: 'qiniu',
type: 'image', type: 'image',
tag1: 'image', tag1: 'image',
objectId: generateNewId(),
filename, filename,
fileType: type, fileType: type,
size, size,
extension, extension,
entity: 'sessionMessage', entity: 'sessionMessage',
bucket: '',
id: generateNewId(), id: generateNewId(),
} as EntityDict['extraFile']['CreateSingle']['data']; } as EntityDict['extraFile']['CreateSingle']['data'];
// try { try {
// // 自己实现上传,并得到图片 url alt href // await this.features.extraFile.upload(
// const { url, bucket } = await this.features.extraFile.upload( // extraFile,
// extraFile // originFileObj
// ); // );
// extraFile.bucket = bucket; const userId = this.features.token.getUserId();
// extraFile.extra1 = null; this.addItem({
// const userId = this.features.token.getUserId(); id: generateNewId(),
// this.addItem({ applicationId,
// id: generateNewId(), sessionId,
// sessionId, createTime: Date.now(),
// type: 'image', aaoe: isEntity,
// extraFile$entity: [ type: 'image',
// { extraFile$entity: [
// id: generateNewId(), {
// action: 'create', id: generateNewId(),
// data: extraFile, action: 'create',
// }, data: extraFile,
// ], },
// } as EntityDict['sessionMessage']['CreateSingle']['data']); ],
// await this.execute(undefined, false); } as EntityDict['sessionMessage']['CreateSingle']['data']);
// } catch (err) { this.features.extraFile2.addLocalFile(extraFile?.id, originFileObj);
// throw err;
// } await this.execute(undefined, false);
} catch (err) {
throw err;
}
}, },
}, },
}); });

View File

@ -7,6 +7,7 @@ import Header from '../../../components/session/forMessage';
import Style from './web.module.less'; import Style from './web.module.less';
import { WebComponentProps } from 'oak-frontend-base'; import { WebComponentProps } from 'oak-frontend-base';
import { EntityDict } from '../../../oak-app-domain'; import { EntityDict } from '../../../oak-app-domain';
import ExtraFileUpload from "@oak-general-business/components/extraFile/upload";
interface customFile { interface customFile {
name: string; name: string;
size: number; size: number;
@ -27,6 +28,7 @@ export default function Render(
isEntity: boolean; isEntity: boolean;
isUser: boolean; isUser: boolean;
employerId: string; employerId: string;
sessionMessageType: string;
}, },
{ {
setButtonHidden: (isHidden: boolean) => void; setButtonHidden: (isHidden: boolean) => void;
@ -45,8 +47,8 @@ export default function Render(
sessionMessageList, sessionMessageList,
oakFullpath, oakFullpath,
text, text,
employerId,
buttonHidden, buttonHidden,
sessionMessageType,
} = data; } = data;
const { const {
setButtonHidden, setButtonHidden,
@ -101,6 +103,7 @@ export default function Render(
pageScroll('comment'); pageScroll('comment');
} }
}; };
console.log(sessionMessageType);
return ( return (
<div className={Style.container}> <div className={Style.container}>
<Header <Header
@ -146,18 +149,35 @@ export default function Render(
<div className={Style.bottom} id="bottom"> <div className={Style.bottom} id="bottom">
<div className={Style.toolbar}> <div className={Style.toolbar}>
<Upload <ExtraFileUpload
oakPath={
data.oakFullpath
? `${data.oakFullpath}.extraFile$entity`
: undefined
}
showUploadList={false}
type="image"
origin="qiniu"
tag1="image"
maxNumber={1}
entity="sessionMessage"
accept="image/*"
>
<PictureOutlined className={Style.icon} />
</ExtraFileUpload>
{/* <Upload
accept={'image/*'} accept={'image/*'}
multiple={false} multiple={false}
showUploadList={false} showUploadList={false}
customRequest={() => { }} // customRequest={() => { }}
onChange={({ file }) => { // onChange={({ file }) => {
customUpload(file as customFile); // customUpload(file as customFile);
}} // }}
> >
<PictureOutlined className={Style.icon} /> <PictureOutlined className={Style.icon} />
</Upload> </Upload> */}
</div> </div>
<div className={Style.textareaBox}> <div className={Style.textareaBox}>
<Input.TextArea <Input.TextArea
ref={textareaRef} ref={textareaRef}