后端 上传微信素材适配

This commit is contained in:
Wang Kejun 2023-09-24 14:55:03 +08:00
parent 48784ed889
commit afefc65639
42 changed files with 2031 additions and 1036 deletions

View File

@ -125,7 +125,7 @@ export type GeneralAspectDict<ED extends EntityDict, Cxt extends BackendRuntimeC
}, context: Cxt) => Promise<any>;
deleteConditionalMenu: (params: {
applicationId: string;
menuid: number;
menuId: number;
}, context: Cxt) => Promise<any>;
batchGetArticle: (params: {
applicationId: string;
@ -135,7 +135,7 @@ export type GeneralAspectDict<ED extends EntityDict, Cxt extends BackendRuntimeC
}, context: Cxt) => Promise<any>;
getArticle: (params: {
applicationId: string;
article_id: string;
articleId: string;
}, context: Cxt) => Promise<any>;
batchGetMaterialList: (params: {
applicationId: string;
@ -146,7 +146,7 @@ export type GeneralAspectDict<ED extends EntityDict, Cxt extends BackendRuntimeC
getMaterial: (params: {
applicationId: string;
type: MenuType;
media_id: string;
mediaId: string;
}, context: Cxt) => Promise<any>;
};
export default GeneralAspectDict;

View File

@ -3,6 +3,7 @@ import { AppType } from "../oak-app-domain/Application/Schema";
import { BackendRuntimeContext } from "../context/BackendRuntimeContext";
import { MediaType } from '../types/WeChat';
import { WebEnv } from 'oak-domain/lib/types/Environment';
import { File } from 'formidable';
export declare function getApplication<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
type: AppType;
domain: string;
@ -18,7 +19,7 @@ export declare function signatureJsSDK<ED extends EntityDict, Cxt extends Backen
}>;
export declare function uploadWechatMedia<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
file: any;
file: File;
type: MediaType;
isPermanent?: string;
description?: string;

View File

@ -60,6 +60,8 @@ export async function signatureJsSDK({ url, env }, context) {
export async function uploadWechatMedia(params, // FormData表单提交 isPermanent 变成 'true' | 'false'
context) {
const { applicationId, file, type: mediaType, isPermanent, description, } = params;
const filename = file.originalFilename;
const filetype = file.mimetype;
const file2 = fs.createReadStream(file.filepath);
const [application] = await context.select('application', {
data: applicationProjection,
@ -78,6 +80,8 @@ context) {
const result = (await wechatInstance.createMaterial({
type: mediaType,
media: file2,
filename,
filetype,
description: description ? JSON.parse(description) : null,
}));
return {
@ -87,6 +91,8 @@ context) {
const result = (await wechatInstance.createTemporaryMaterial({
type: mediaType,
media: file2,
filename,
filetype,
}));
return {
mediaId: result.media_id,

View File

@ -17,7 +17,7 @@ export declare function createConditionalMenu<ED extends EntityDict, Cxt extends
}, context: Cxt): Promise<any>;
export declare function deleteConditionalMenu<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
menuid: number;
menuId: number;
}, context: Cxt): Promise<any>;
export declare function batchGetArticle<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
@ -27,7 +27,7 @@ export declare function batchGetArticle<ED extends EntityDict, Cxt extends Backe
}, context: Cxt): Promise<any>;
export declare function getArticle<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
article_id: string;
articleId: string;
}, context: Cxt): Promise<any>;
export declare function batchGetMaterialList<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
@ -38,5 +38,5 @@ export declare function batchGetMaterialList<ED extends EntityDict, Cxt extends
export declare function getMaterial<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
type: MenuType;
media_id: string;
mediaId: string;
}, context: Cxt): Promise<any>;

View File

@ -77,7 +77,7 @@ export async function deleteConditionalMenu(params, context) {
appId = config2.appId;
appSecret = config2.appSecret;
const wechatInstance = WechatSDK.getInstance(appId, type, appSecret);
const result = await wechatInstance.deleteConditionalMenu(params.menuid);
const result = await wechatInstance.deleteConditionalMenu(params.menuId);
return result;
}
export async function batchGetArticle(params, context) {
@ -103,7 +103,9 @@ export async function getArticle(params, context) {
appId = config2.appId;
appSecret = config2.appSecret;
const wechatInstance = WechatSDK.getInstance(appId, type, appSecret);
const result = await wechatInstance.getArticle(params);
const result = await wechatInstance.getArticle({
articleId: params.articleId,
});
return result;
}
export async function batchGetMaterialList(params, context) {
@ -129,6 +131,8 @@ export async function getMaterial(params, context) {
appId = config2.appId;
appSecret = config2.appSecret;
const wechatInstance = WechatSDK.getInstance(appId, type, appSecret);
const result = await wechatInstance.getMaterial(params);
const result = await wechatInstance.getMaterial({
mediaId: params.mediaId,
});
return result;
}

View File

@ -25,4 +25,4 @@ export default function render(props: WebComponentProps<EntityDict, 'extraFile',
}, {
onRemove: (file: UploadFile) => void;
addFileByWeb: (file: UploadFile) => void;
}>): JSX.Element;
}>): import("react/jsx-runtime").JSX.Element;

View File

@ -97,9 +97,13 @@ export default OakComponent({
return false;
}
},
async getMaterialImg(media_id) {
async getMaterialImg(mediaId) {
const { applicationId } = this.props;
const imgFile = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type: 'image', media_id });
const imgFile = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type: 'image',
mediaId,
});
return new Promise((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);

View File

@ -4,7 +4,7 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps<
config: any;
menuIndex: number;
changeConfig: (config: any) => void;
changePublishState: (publish: "wait" | "success" | "fail") => void;
changePublishState: (publish: 'wait' | 'success' | 'fail') => void;
getErrorIndex: (errorIndex: number[]) => void;
createMenu: () => Promise<void>;
selectedBtn: number;

View File

@ -24,7 +24,8 @@ export default OakComponent({
setConfig(index, content, currentIndex) {
const { config, changeConfig } = this.props;
if (typeof currentIndex === 'number') {
content.name = config.button[currentIndex].sub_button[index].name;
content.name =
config.button[currentIndex].sub_button[index].name;
config.button[currentIndex].sub_button[index] = content;
changeConfig(config);
}
@ -36,7 +37,10 @@ export default OakComponent({
}
},
confirmName(menuName) {
if (Object.prototype.toString.call(menuName).slice(8, -1).toLowerCase() !== 'string') {
if (Object.prototype.toString
.call(menuName)
.slice(8, -1)
.toLowerCase() !== 'string') {
throw Error('param str type error ');
}
else if (!menuName) {
@ -45,13 +49,16 @@ export default OakComponent({
else if (!/^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(menuName)) {
return '字符串中包含除中文、数字、英文以外的字符!';
}
else if (menuName.replace(/[\u4e00-\u9fa5]/g, "**").length > 8) {
else if (menuName.replace(/[\u4e00-\u9fa5]/g, '**').length > 8) {
return '字符串长度超过限制!';
}
return '';
},
confirmSubName(menuName) {
if (Object.prototype.toString.call(menuName).slice(8, -1).toLowerCase() !== 'string') {
if (Object.prototype.toString
.call(menuName)
.slice(8, -1)
.toLowerCase() !== 'string') {
throw Error('param str type error ');
}
else if (!menuName) {
@ -60,7 +67,7 @@ export default OakComponent({
else if (!/^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(menuName)) {
return '字符串中包含除中文、数字、英文以外的字符!';
}
else if (menuName.replace(/[\u4e00-\u9fa5]/g, "**").length > 16) {
else if (menuName.replace(/[\u4e00-\u9fa5]/g, '**').length > 16) {
return '字符串长度超过限制!';
}
return '';
@ -85,35 +92,49 @@ export default OakComponent({
deleteMenuContent(index, currentIndex) {
const { config, changeConfig } = this.props;
if (typeof currentIndex === 'number') {
config.button[currentIndex].sub_button[index] = { name: config.button[currentIndex].sub_button[index].name };
config.button[currentIndex].sub_button[index] = {
name: config.button[currentIndex].sub_button[index].name,
};
changeConfig(config);
}
else {
config.button[index] = { name: config.button[index].name, sub_button: [...config.button[index].sub_button] };
config.button[index] = {
name: config.button[index].name,
sub_button: [...config.button[index].sub_button],
};
changeConfig(config);
}
},
async getMaterialImgAndVoice(type, media_id) {
async getMaterialImgAndVoice(type, mediaId) {
const { applicationId } = this.props;
return new Promise((resolve, reject) => {
this.features.wechatMenu.getMaterial({ applicationId: applicationId, type, media_id })
.then(file => {
this.features.wechatMenu
.getMaterial({
applicationId: applicationId,
type,
mediaId,
})
.then((file) => {
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
resolve(e.target?.result);
};
})
.catch(error => {
.catch((error) => {
reject(error);
});
});
},
async getMaterialVideo(media_id) {
async getMaterialVideo(mediaId) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type: 'video', media_id });
const result = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type: 'video',
mediaId,
});
if (result && result.down_url) {
return { url: result.down_url, media_id };
return { url: result.down_url, media_id: mediaId };
}
},
decideMenuContentLabel(decidedMenuContent, type) {
@ -138,15 +159,18 @@ export default OakComponent({
return '文字'; // 默认值
}
},
async getArticle(article_id) {
async getArticle(articleId) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getArticle({ applicationId: applicationId, article_id });
const result = await this.features.wechatMenu.getArticle({
applicationId: applicationId,
articleId,
});
if (result && result.news_item) {
const modifiedResult = await Promise.all(result.news_item.map(async (ele) => {
const coverUrl = await this.getMaterialImgAndVoice('image', ele.thumb_media_id);
return {
...ele,
coverUrl
coverUrl,
};
}));
return modifiedResult;
@ -158,13 +182,15 @@ export default OakComponent({
arr.map((ele, index) => {
if (ele.sub_button && ele.sub_button.length > 0) {
ele.sub_button.map((ele, index2) => {
if (Object.keys(ele).length === 1 && ele.hasOwnProperty('name')) {
if (Object.keys(ele).length === 1 &&
ele.hasOwnProperty('name')) {
errorIndex.push((index + 1) * 10 + index2);
}
});
}
else {
if (Object.keys(ele).length === 2 && ele.hasOwnProperty('name')) {
if (Object.keys(ele).length === 2 &&
ele.hasOwnProperty('name')) {
console.log(index);
errorIndex.push(index);
}
@ -180,19 +206,20 @@ export default OakComponent({
if (errorInfo) {
this.setMessage({
type: 'warning',
content: '菜单名称有误'
content: '菜单名称有误',
});
return;
}
if (errorUrlInfo) {
this.setMessage({
type: 'warning',
content: '公众号链接有误'
content: '公众号链接有误',
});
return;
}
const { applicationId, config, changeConfig, changePublishState, createMenu, menuType, changeMenuId } = this.props;
if (this.checkError(config.button).length === 0 && config.button.length > 0) {
const { applicationId, config, changeConfig, changePublishState, createMenu, menuType, changeMenuId, } = this.props;
if (this.checkError(config.button).length === 0 &&
config.button.length > 0) {
changeConfig(config);
const removeSubTypeAndContent = (obj) => {
const { subType, content, ...newObj } = obj;
@ -208,7 +235,10 @@ export default OakComponent({
}
});
if (menuType === 'common') {
const result = await this.features.wechatMenu.createMenu({ applicationId: applicationId, menuConfig: { button: menuConfig } });
const result = await this.features.wechatMenu.createMenu({
applicationId: applicationId,
menuConfig: { button: menuConfig },
});
if (result.success) {
changePublishState('success');
}
@ -218,8 +248,14 @@ export default OakComponent({
await createMenu();
}
else {
const button = { button: menuConfig, matchrule: config.matchrule };
const result = await this.features.wechatMenu.createConditionalMenu({ applicationId: applicationId, menuConfig: button });
const button = {
button: menuConfig,
matchrule: config.matchrule,
};
const result = await this.features.wechatMenu.createConditionalMenu({
applicationId: applicationId,
menuConfig: button,
});
if (result.success) {
changeMenuId(result.menuid);
changePublishState('success');
@ -234,14 +270,14 @@ export default OakComponent({
if (config.button.length === 0) {
this.setMessage({
content: '请添加自定义菜单',
type: 'warning'
type: 'warning',
});
return;
}
if ((this.checkError(config.button).length > 0)) {
if (this.checkError(config.button).length > 0) {
this.setMessage({
content: '请添加菜单消息',
type: 'warning'
type: 'warning',
});
return;
}
@ -249,7 +285,7 @@ export default OakComponent({
},
async deleteConditionalMenu() {
const { applicationId, deleteMenu, menuIndex, menuId, createMenu } = this.props;
const result = await this.features.wechatMenu.deleteConditionalMenu({ applicationId: applicationId, menuid: menuId });
const result = await this.features.wechatMenu.deleteConditionalMenu({ applicationId: applicationId, menuId: menuId });
if (result.success) {
deleteMenu();
await createMenu();
@ -257,9 +293,9 @@ export default OakComponent({
else {
this.setMessage({
type: 'error',
content: result.errmsg
content: result.errmsg,
});
}
}
}
},
},
});

View File

@ -28,8 +28,8 @@ export default function Render(props: WebComponentProps<EntityDict, keyof Entity
toDown: (currentIndex: number, index: number) => void;
editMenuName: (index: number, name: string, currentIndex?: number) => void;
deleteMenuContent: (index: number, currentIndex?: number) => void;
getMaterialImgAndVoice: (type: string, media_id: string) => Promise<string>;
getMaterialVideo: (media_id: string) => void;
getMaterialImgAndVoice: (type: string, mediaId: string) => Promise<string>;
getMaterialVideo: (mediaId: string) => void;
decideMenuContentLabel: (obj: any, type: 'news' | 'image' | 'video' | 'voice' | 'text') => string;
getArticle: (article_id: string) => void;
createMenu: (errorInfo: string, errorUrlInfo: string) => void;

View File

@ -13,7 +13,7 @@ import SelectArticle from '../selectArticle';
import TextClick from '../textClick';
export default function Render(props) {
const { data, methods } = props;
const { config, menuIndex, selectedBtn, selectedSubBtn, currentIndex, changeIsPreview, getOpen, menuType, applicationId, menuId } = data;
const { config, menuIndex, selectedBtn, selectedSubBtn, currentIndex, changeIsPreview, getOpen, menuType, applicationId, menuId, } = data;
const { setConfig, confirmName, confirmSubName, editMenuName, deleteMenuContent, getMaterialImgAndVoice, getMaterialVideo, decideMenuContentLabel, getArticle, createMenu, deleteConditionalMenu, confirmUrl, } = methods;
const [msgType, setMsgType] = useState('sendMsg');
const [errorInfo, setErrorInfo] = useState('');
@ -32,10 +32,20 @@ export default function Render(props) {
setMenuContent(menuContent);
if (msgType === 'miniprogram') {
if (selectedBtn > 0) {
setConfig(selectedBtn - 1, { type: 'miniprogram', url: menuContent.url, pagepath: menuContent.pagepath, appid: menuContent.appid });
setConfig(selectedBtn - 1, {
type: 'miniprogram',
url: menuContent.url,
pagepath: menuContent.pagepath,
appid: menuContent.appid,
});
}
else {
setConfig(selectedSubBtn - 1, { type: 'miniprogram', url: menuContent.url, pagepath: menuContent.pagepath, appid: menuContent.appid }, currentIndex);
setConfig(selectedSubBtn - 1, {
type: 'miniprogram',
url: menuContent.url,
pagepath: menuContent.pagepath,
appid: menuContent.appid,
}, currentIndex);
}
}
};
@ -46,10 +56,20 @@ export default function Render(props) {
const getDecidedMenuContent = async (menuContent) => {
setDecidedMenuContent(menuContent);
if (selectedBtn > 0) {
setConfig(selectedBtn - 1, { type: 'click', key: await generateNewIdAsync(), subType: 'text', content: menuContent });
setConfig(selectedBtn - 1, {
type: 'click',
key: await generateNewIdAsync(),
subType: 'text',
content: menuContent,
});
}
else {
setConfig(selectedSubBtn - 1, { type: 'click', key: await generateNewIdAsync(), subType: 'text', content: menuContent }, currentIndex);
setConfig(selectedSubBtn - 1, {
type: 'click',
key: await generateNewIdAsync(),
subType: 'text',
content: menuContent,
}, currentIndex);
}
};
useEffect(() => {
@ -62,13 +82,18 @@ export default function Render(props) {
useEffect(() => {
const fetchData = async (id, type) => {
if (type === 'news') {
setDecidedMenuContent({ content: { news_item: await getArticle(id) } });
setDecidedMenuContent({
content: { news_item: await getArticle(id) },
});
}
if (type === 'video') {
setDecidedMenuContent(await getMaterialVideo(id));
}
if (type === 'image' || type === 'voice') {
setDecidedMenuContent({ url: await getMaterialImgAndVoice(type, id), media_id: id });
setDecidedMenuContent({
url: await getMaterialImgAndVoice(type, id),
media_id: id,
});
}
};
if (selectedBtn !== 0) {
@ -103,7 +128,7 @@ export default function Render(props) {
setMenuContent({
appid: menuConfig.appid,
url: menuConfig.url,
pagepath: menuConfig.pagepath
pagepath: menuConfig.pagepath,
});
}
else if (menuConfig?.type === 'view') {
@ -122,13 +147,18 @@ export default function Render(props) {
useEffect(() => {
const fetchData = async (id, type) => {
if (type === 'news') {
setDecidedMenuContent({ content: { news_item: await getArticle(id) } });
setDecidedMenuContent({
content: { news_item: await getArticle(id) },
});
}
if (type === 'video') {
setDecidedMenuContent(await getMaterialVideo(id));
}
if (type === 'image' || type === 'voice') {
setDecidedMenuContent({ url: await getMaterialImgAndVoice(type, id), media_id: id });
setDecidedMenuContent({
url: await getMaterialImgAndVoice(type, id),
media_id: id,
});
}
};
if (selectedSubBtn !== 0) {
@ -163,7 +193,7 @@ export default function Render(props) {
setMenuContent({
appid: subMenuConfig.appid,
url: subMenuConfig.url,
pagepath: subMenuConfig.pagepath
pagepath: subMenuConfig.pagepath,
});
}
else if (subMenuConfig?.type === 'view') {
@ -189,7 +219,10 @@ export default function Render(props) {
}
}
}, [url]);
return (_jsx("div", { className: Style.container, children: config && config.button && config.button.length > 0 && (selectedBtn !== 0 || selectedSubBtn !== 0) ? (_jsxs("div", { className: Style.upsertMenu, children: [_jsxs("div", { className: Style.content, children: [_jsx("div", { className: Style.title, children: selectedSubBtn !== 0 ? '子菜单信息' : '菜单信息' }), _jsx("div", { style: { marginBottom: 32 }, children: _jsx(Form.Item, { label: _jsx("div", { className: Style.label, children: "\u540D\u79F0" }), colon: false, help: _jsxs("div", { children: [_jsx("div", { children: `仅支持中英文和数字,字数不超过${selectedSubBtn !== 0 ? 8 : 4}个汉字或${selectedSubBtn !== 0 ? 16 : 8}个字母。` }), errorInfo && _jsx("div", { style: { color: '#fa5151' }, children: errorInfo })] }), children: _jsx(Input, { style: { width: 340 }, onChange: (val) => {
return (_jsx("div", { className: Style.container, children: config &&
config.button &&
config.button.length > 0 &&
(selectedBtn !== 0 || selectedSubBtn !== 0) ? (_jsxs("div", { className: Style.upsertMenu, children: [_jsxs("div", { className: Style.content, children: [_jsx("div", { className: Style.title, children: selectedSubBtn !== 0 ? '子菜单信息' : '菜单信息' }), _jsx("div", { style: { marginBottom: 32 }, children: _jsx(Form.Item, { label: _jsx("div", { className: Style.label, children: "\u540D\u79F0" }), colon: false, help: _jsxs("div", { children: [_jsx("div", { children: `仅支持中英文和数字,字数不超过${selectedSubBtn !== 0 ? 8 : 4}个汉字或${selectedSubBtn !== 0 ? 16 : 8}个字母。` }), errorInfo && (_jsx("div", { style: { color: '#fa5151' }, children: errorInfo }))] }), children: _jsx(Input, { style: { width: 340 }, onChange: (val) => {
setMenuName(val.target.value);
if (selectedSubBtn !== 0) {
setErrorInfo(confirmSubName(val.target.value));
@ -203,8 +236,11 @@ export default function Render(props) {
editMenuName(selectedBtn - 1, val.target.value);
}
}
}, status: errorInfo ? 'error' : '', value: menuName }) }) }), config.button[currentIndex]?.sub_button?.length === 0 && selectedSubBtn === 0
|| selectedSubBtn > 0 ? (_jsxs(_Fragment, { children: [_jsx(Form.Item, { colon: false, label: _jsx("div", { className: Style.label, children: "\u6D88\u606F\u7C7B\u578B" }), children: _jsxs(Radio.Group, { value: msgType, onChange: (val) => setMsgType(val.target.value), children: [_jsx(Radio, { value: 'sendMsg', children: "\u53D1\u9001\u6D88\u606F" }), _jsx(Radio, { value: 'view', children: "\u8DF3\u8F6C\u9875\u9762" }), _jsx(Radio, { value: 'miniprogram', children: "\u8DF3\u8F6C\u5C0F\u7A0B\u5E8F" })] }) }), msgType === 'sendMsg' ? (_jsxs(_Fragment, { children: [_jsxs(Form.Item, { colon: false, label: _jsx("div", { className: Style.label, children: decideMenuContentLabel(decidedMenuContent, type) }), children: [!decidedMenuContent && type !== 'text' ? _jsxs("div", { className: Style.menuContent, children: [_jsx("div", { className: Style.item, onClick: () => {
}, status: errorInfo ? 'error' : '', value: menuName }) }) }), (config.button[currentIndex]?.sub_button?.length ===
0 &&
selectedSubBtn === 0) ||
selectedSubBtn > 0 ? (_jsxs(_Fragment, { children: [_jsx(Form.Item, { colon: false, label: _jsx("div", { className: Style.label, children: "\u6D88\u606F\u7C7B\u578B" }), children: _jsxs(Radio.Group, { value: msgType, onChange: (val) => setMsgType(val.target.value), children: [_jsx(Radio, { value: 'sendMsg', children: "\u53D1\u9001\u6D88\u606F" }), _jsx(Radio, { value: 'view', children: "\u8DF3\u8F6C\u9875\u9762" }), _jsx(Radio, { value: 'miniprogram', children: "\u8DF3\u8F6C\u5C0F\u7A0B\u5E8F" })] }) }), msgType === 'sendMsg' ? (_jsxs(_Fragment, { children: [_jsxs(Form.Item, { colon: false, label: _jsx("div", { className: Style.label, children: decideMenuContentLabel(decidedMenuContent, type) }), children: [!decidedMenuContent &&
type !== 'text' ? (_jsxs("div", { className: Style.menuContent, children: [_jsx("div", { className: Style.item, onClick: () => {
setOpen(true);
getOpen(true);
setType('news');
@ -222,152 +258,213 @@ export default function Render(props) {
setOpen(true);
getOpen(true);
setType('video');
}, children: "\u89C6\u9891" })] })
: type === 'image' ?
_jsxs("div", { className: Style.coverImage, children: [_jsx("img", { className: Style.img, src: decidedMenuContent.url }), _jsxs("div", { className: Style.buttonGroup, children: [_jsx("div", { className: Style.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该图片吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
}
;
},
});
}, children: _jsx(DeleteOutlined, {}) }), _jsx("div", { className: Style.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: _jsx(SwapOutlined, {}) })] })] })
: type === 'voice' ?
_jsxs("div", { className: Style.fileCover, children: [_jsxs("a", { href: decidedMenuContent.url, download: true, style: { color: '#1677FF', cursor: 'pointer' }, children: [_jsx(DownloadOutlined, {}), decidedMenuContent.media_id] }), _jsxs("div", { className: Style.buttonGroup, children: [_jsx("div", { className: Style.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该音频吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
}
;
},
});
}, children: _jsx(DeleteOutlined, {}) }), _jsx("div", { className: Style.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: _jsx(SwapOutlined, {}) })] })] })
: type === 'video' ?
_jsxs("div", { className: Style.fileCover, children: [_jsxs("a", { href: decidedMenuContent.url, download: true, style: { color: '#1677FF', cursor: 'pointer' }, children: [_jsx(DownloadOutlined, {}), decidedMenuContent.media_id] }), _jsxs("div", { className: Style.buttonGroup, children: [_jsx("div", { className: Style.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该视频吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
}
;
},
});
}, children: _jsx(DeleteOutlined, {}) }), _jsx("div", { className: Style.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: _jsx(SwapOutlined, {}) })] })] })
: type === 'news' ?
_jsxs("div", { className: Style.news, children: [_jsx(ShowNews, { news: decidedMenuContent?.content?.news_item, oakAutoUnmount: false }), _jsxs("div", { className: Style.buttonGroup, style: { height: '100%' }, children: [_jsx("div", { className: Style.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该图文信息吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
}
;
},
});
}, children: _jsx(DeleteOutlined, {}) }), _jsx("div", { className: Style.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: _jsx(SwapOutlined, {}) })] })] })
: null, type === 'text' &&
_jsxs("div", { className: Style.editor, children: [_jsx(TextClick, { oakAutoUnmount: true, value: decidedMenuContent, getDecidedMenuContent: getDecidedMenuContent }), _jsx("div", { className: Style.buttonGroup, style: { height: 36, position: 'absolute', right: -50 }, children: _jsx("div", { className: Style.buttonItem, onClick: () => {
}, children: "\u89C6\u9891" })] })) : type === 'image' ? (_jsxs("div", { className: Style.coverImage, children: [_jsx("img", { className: Style.img, src: decidedMenuContent.url }), _jsxs("div", { className: Style.buttonGroup, children: [_jsx("div", { className: Style.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该文字吗?',
title: '确定删除该图片吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setType('news');
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: _jsx(DeleteOutlined, {}) }) })] })] }), _jsx(Modal, { open: open, footer: _jsxs(Space, { children: [_jsx(Button, { type: 'primary', disabled: !menuContent, onClick: () => {
}, children: _jsx(DeleteOutlined, {}) }), _jsx("div", { className: Style.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: _jsx(SwapOutlined, {}) })] })] })) : type === 'voice' ? (_jsxs("div", { className: Style.fileCover, children: [_jsxs("a", { href: decidedMenuContent.url, download: true, style: {
color: '#1677FF',
cursor: 'pointer',
}, children: [_jsx(DownloadOutlined, {}), decidedMenuContent.media_id] }), _jsxs("div", { className: Style.buttonGroup, children: [_jsx("div", { className: Style.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该音频吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: _jsx(DeleteOutlined, {}) }), _jsx("div", { className: Style.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: _jsx(SwapOutlined, {}) })] })] })) : type === 'video' ? (_jsxs("div", { className: Style.fileCover, children: [_jsxs("a", { href: decidedMenuContent.url, download: true, style: {
color: '#1677FF',
cursor: 'pointer',
}, children: [_jsx(DownloadOutlined, {}), decidedMenuContent.media_id] }), _jsxs("div", { className: Style.buttonGroup, children: [_jsx("div", { className: Style.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该视频吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: _jsx(DeleteOutlined, {}) }), _jsx("div", { className: Style.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: _jsx(SwapOutlined, {}) })] })] })) : type === 'news' ? (_jsxs("div", { className: Style.news, children: [_jsx(ShowNews, { news: decidedMenuContent
?.content
?.news_item, oakAutoUnmount: false }), _jsxs("div", { className: Style.buttonGroup, style: {
height: '100%',
}, children: [_jsx("div", { className: Style.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该图文信息吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: _jsx(DeleteOutlined, {}) }), _jsx("div", { className: Style.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: _jsx(SwapOutlined, {}) })] })] })) : null, type === 'text' && (_jsxs("div", { className: Style.editor, children: [_jsx(TextClick, { oakAutoUnmount: true, value: decidedMenuContent, getDecidedMenuContent: getDecidedMenuContent }), _jsx("div", { className: Style.buttonGroup, style: {
height: 36,
position: 'absolute',
right: -50,
}, children: _jsx("div", { className: Style.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该文字吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setType('news');
setDecidedMenuContent(null);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: _jsx(DeleteOutlined, {}) }) })] }))] }), _jsx(Modal, { open: open, footer: _jsxs(Space, { children: [_jsx(Button, { type: 'primary', disabled: !menuContent, onClick: () => {
setOpen(false);
getOpen(false);
setDecidedMenuContent(menuContent);
if (selectedBtn > 0) {
if (type !== 'news') {
if (type === 'image') {
setConfig(selectedBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'image' });
if (type !==
'news') {
if (type ===
'image') {
setConfig(selectedBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'image',
});
}
if (type === 'voice') {
setConfig(selectedBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'voice' });
if (type ===
'voice') {
setConfig(selectedBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'voice',
});
}
if (type === 'video') {
setConfig(selectedBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'video' });
if (type ===
'video') {
setConfig(selectedBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'video',
});
}
}
else {
setConfig(selectedBtn - 1, { type: 'article_id', article_id: menuContent.article_id });
setConfig(selectedBtn -
1, {
type: 'article_id',
article_id: menuContent.article_id,
});
}
}
else {
if (type !== 'news') {
if (type === 'image') {
setConfig(selectedSubBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'image' }, currentIndex);
if (type !==
'news') {
if (type ===
'image') {
setConfig(selectedSubBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'image',
}, currentIndex);
}
if (type === 'voice') {
setConfig(selectedSubBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'voice' }, currentIndex);
if (type ===
'voice') {
setConfig(selectedSubBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'voice',
}, currentIndex);
}
if (type === 'video') {
setConfig(selectedSubBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'video' }, currentIndex);
if (type ===
'video') {
setConfig(selectedSubBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'video',
}, currentIndex);
}
}
else {
setConfig(selectedSubBtn - 1, { type: 'article_id', article_id: menuContent.article_id }, currentIndex);
setConfig(selectedSubBtn -
1, {
type: 'article_id',
article_id: menuContent.article_id,
}, currentIndex);
}
}
}, children: "\u786E\u5B9A" }), _jsx(Button, { type: 'default', onClick: () => {
@ -378,15 +475,29 @@ export default function Render(props) {
setOpen(false);
getOpen(false);
setMenuContent(null);
}, destroyOnClose: true, width: 960, children: _jsx(WechatMaterialLibrary, { oakAutoUnmount: true, type: type, getMenuContent: getMenuContent, applicationId: applicationId }) })] })) : msgType === 'view' ? (_jsxs(Form.Item, { colon: false, label: _jsx("div", { className: Style.label, children: "\u7F51\u9875\u94FE\u63A5" }), help: _jsx(_Fragment, { children: errorUrlInfo && _jsx("div", { style: { color: '#fa5151' }, children: errorUrlInfo }) }), children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx(Input, { placeholder: '\u516C\u4F17\u53F7\u94FE\u63A5:\u8BF7\u4EE5https://\u6216http://\u5F00\u5934', style: { width: 340 }, value: url, onChange: (val) => {
}, destroyOnClose: true, width: 960, children: _jsx(WechatMaterialLibrary, { oakAutoUnmount: true, type: type, getMenuContent: getMenuContent, applicationId: applicationId }) })] })) : msgType === 'view' ? (_jsxs(Form.Item, { colon: false, label: _jsx("div", { className: Style.label, children: "\u7F51\u9875\u94FE\u63A5" }), help: _jsx(_Fragment, { children: errorUrlInfo && (_jsx("div", { style: {
color: '#fa5151',
}, children: errorUrlInfo })) }), children: [_jsxs("div", { style: {
display: 'flex',
flexDirection: 'column',
}, children: [_jsx(Input, { placeholder: "\u516C\u4F17\u53F7\u94FE\u63A5:\u8BF7\u4EE5https://\u6216http://\u5F00\u5934", style: { width: 340 }, value: url, onChange: (val) => {
setUrl(val.target.value);
setErrorUrlInfo(confirmUrl(val.target.value));
}, status: errorUrlInfo ? 'error' : '' }), _jsx("a", { style: { padding: '10px 0' }, onClick: () => { setOpen(true); getOpen(true); }, children: "\u9009\u62E9\u56FE\u6587\u94FE\u63A5" })] }), _jsx(Modal, { open: open, footer: null, title: '选择图文链接', onCancel: () => { setOpen(false); getOpen(false); }, width: 600, children: _jsx(SelectArticle, { oakAutoUnmount: true, changeOpen: changeOpen, getUrl: getUrl, applicationId: applicationId }) })] })) : (_jsxs(Form.Item, { colon: false, label: _jsx("div", { className: Style.label, children: "\u5C0F\u7A0B\u5E8F" }), children: [_jsx(Button, { onClick: () => {
}, status: errorUrlInfo ? 'error' : '' }), _jsx("a", { style: { padding: '10px 0' }, onClick: () => {
setOpen(true);
getOpen(true);
}, children: "\u9009\u62E9\u56FE\u6587\u94FE\u63A5" })] }), _jsx(Modal, { open: open, footer: null, title: '选择图文链接', onCancel: () => {
setOpen(false);
getOpen(false);
}, width: 600, children: _jsx(SelectArticle, { oakAutoUnmount: true, changeOpen: changeOpen, getUrl: getUrl, applicationId: applicationId }) })] })) : (_jsxs(Form.Item, { colon: false, label: _jsx("div", { className: Style.label, children: "\u5C0F\u7A0B\u5E8F" }), children: [_jsx(Button, { onClick: () => {
setOpen(true);
getOpen(true);
}, children: "\u9009\u62E9\u5C0F\u7A0B\u5E8F" }), menuContent && menuContent.appid && _jsx("div", { children: menuContent.appid }), _jsx(Modal, { title: '添加小程序', open: open, footer: null, onCancel: () => { setOpen(false); getOpen(false); }, children: _jsx(SelectMiniprogram, { oakAutoUnmount: true, getMenuContent: getMenuContent, changeOpen: changeOpen }) })] }))] })) : (null)] }), _jsx("div", { className: Style.actionBar, children: _jsxs(Space, { children: [_jsxs(Button, { onClick: () => changeIsPreview(true), children: [_jsx(EyeOutlined, {}), "\u9884\u89C8"] }), _jsxs(Button, { type: 'primary', onClick: async () => {
}, children: "\u9009\u62E9\u5C0F\u7A0B\u5E8F" }), menuContent && menuContent.appid && (_jsx("div", { children: menuContent.appid })), _jsx(Modal, { title: '添加小程序', open: open, footer: null, onCancel: () => {
setOpen(false);
getOpen(false);
}, children: _jsx(SelectMiniprogram, { oakAutoUnmount: true, getMenuContent: getMenuContent, changeOpen: changeOpen }) })] }))] })) : null] }), _jsx("div", { className: Style.actionBar, children: _jsxs(Space, { children: [_jsxs(Button, { onClick: () => changeIsPreview(true), children: [_jsx(EyeOutlined, {}), "\u9884\u89C8"] }), _jsxs(Button, { type: "primary", onClick: async () => {
createMenu(errorInfo, errorUrlInfo);
}, children: [_jsx(CheckOutlined, {}), "\u53D1\u5E03"] }), menuType === 'conditional' && config && menuId && _jsxs(Button, { type: 'primary', danger: true, onClick: () => {
}, children: [_jsx(CheckOutlined, {}), "\u53D1\u5E03"] }), menuType === 'conditional' && config && menuId && (_jsxs(Button, { type: "primary", danger: true, onClick: () => {
const modal = confirm({
title: '确定删除该个性化菜单吗?',
content: '删除后不可恢复',
@ -397,7 +508,7 @@ export default function Render(props) {
modal.destroy();
},
});
}, children: [_jsx(DeleteOutlined, {}), "\u5220\u9664"] })] }) })] })) : (_jsxs("div", { className: Style.empty, children: [_jsx("div", { className: Style.content, children: "\u4F60\u672A\u6DFB\u52A0\u81EA\u5B9A\u4E49\u83DC\u5355\uFF0C\u70B9\u51FB\u5DE6\u4FA7\u6DFB\u52A0\u83DC\u5355\u4E3A\u516C\u4F17\u53F7\u521B\u5EFA\u83DC\u5355\u680F\u3002" }), _jsx("div", { className: Style.actionBar, children: _jsxs(Space, { children: [_jsxs(Button, { onClick: () => changeIsPreview(true), children: [_jsx(EyeOutlined, {}), "\u9884\u89C8"] }), _jsxs(Button, { type: 'primary', onClick: async () => {
}, children: [_jsx(DeleteOutlined, {}), "\u5220\u9664"] }))] }) })] })) : (_jsxs("div", { className: Style.empty, children: [_jsx("div", { className: Style.content, children: "\u4F60\u672A\u6DFB\u52A0\u81EA\u5B9A\u4E49\u83DC\u5355\uFF0C\u70B9\u51FB\u5DE6\u4FA7\u6DFB\u52A0\u83DC\u5355\u4E3A\u516C\u4F17\u53F7\u521B\u5EFA\u83DC\u5355\u680F\u3002" }), _jsx("div", { className: Style.actionBar, children: _jsxs(Space, { children: [_jsxs(Button, { onClick: () => changeIsPreview(true), children: [_jsx(EyeOutlined, {}), "\u9884\u89C8"] }), _jsxs(Button, { type: "primary", onClick: async () => {
createMenu(errorInfo, errorUrlInfo);
}, children: [_jsx(CheckOutlined, {}), "\u53D1\u5E03"] })] }) })] })) }));
}

View File

@ -7,9 +7,13 @@ export default OakComponent({
},
data: {},
methods: {
async getMaterialImgAndVoice(type, media_id) {
async getMaterialImgAndVoice(type, mediaId) {
const { applicationId } = this.props;
const imgFile = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type, media_id });
const imgFile = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type,
mediaId,
});
return new Promise((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);
@ -18,26 +22,33 @@ export default OakComponent({
};
});
},
async getArticle(article_id) {
async getArticle(articleId) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getArticle({ applicationId: applicationId, article_id });
const result = await this.features.wechatMenu.getArticle({
applicationId: applicationId,
articleId,
});
if (result && result.news_item) {
const modifiedResult = await Promise.all(result.news_item.map(async (ele) => {
const coverUrl = await this.getMaterialImgAndVoice('image', ele.thumb_media_id);
return {
...ele,
coverUrl
coverUrl,
};
}));
return modifiedResult;
}
},
async getMaterialVideo(media_id) {
async getMaterialVideo(mediaId) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type: 'video', media_id });
const result = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type: 'video',
mediaId,
});
if (result && result.down_url) {
return { url: result.down_url, media_id };
return { url: result.down_url, media_id: mediaId };
}
},
}
},
});

View File

@ -7,7 +7,7 @@ export default function Render(props: WebComponentProps<EntityDict, keyof Entity
}, {
getMaterialImgAndVoice: (type: 'image' | 'voice', media_id: string) => Promise<string>;
getArticle: (article_id: string) => Promise<any[]>;
getMaterialVideo: (media_id: string) => {
getMaterialVideo: (mediaId: string) => {
url: string;
media_id: string;
};

View File

@ -11,27 +11,32 @@ export default OakComponent({
if (applicationId) {
this.getArticleList(1);
}
}
},
},
methods: {
async getArticleList(page) {
const { applicationId } = this.props;
const offset = (page - 1) * 10;
const result = await this.features.wechatMenu.batchGetArticle({ applicationId: applicationId, offset, count: 10, noContent: 0 });
const result = await this.features.wechatMenu.batchGetArticle({
applicationId: applicationId,
offset,
count: 10,
noContent: 0,
});
const modifiedResult = await Promise.all(result.item.map(async (ele) => {
const news_item = await Promise.all(ele.content.news_item.map(async (ele2) => {
const coverUrl = await this.getMaterialImg(ele2.thumb_media_id);
return {
...ele2,
coverUrl
coverUrl,
};
}));
return {
...ele,
content: {
...ele.content,
news_item
}
news_item,
},
};
}));
this.setState({
@ -39,9 +44,13 @@ export default OakComponent({
total: result.total_count,
});
},
async getMaterialImg(media_id) {
async getMaterialImg(mediaId) {
const { applicationId } = this.props;
const imgFile = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type: 'image', media_id });
const imgFile = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type: 'image',
mediaId,
});
return new Promise((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);
@ -49,6 +58,6 @@ export default OakComponent({
resolve(e.target?.result);
};
});
}
}
},
},
});

View File

@ -27,7 +27,7 @@ export declare class WechatMenu<ED extends EntityDict, Cxt extends BackendRuntim
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["createConditionalMenu"]>>;
deleteConditionalMenu(params: {
applicationId: string;
menuid: number;
menuId: number;
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["deleteConditionalMenu"]>>;
batchGetArticle(params: {
applicationId: string;
@ -37,7 +37,7 @@ export declare class WechatMenu<ED extends EntityDict, Cxt extends BackendRuntim
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["batchGetArticle"]>>;
getArticle(params: {
applicationId: string;
article_id: string;
articleId: string;
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["getArticle"]>>;
createMaterial(params: {
applicationId: string;
@ -55,6 +55,6 @@ export declare class WechatMenu<ED extends EntityDict, Cxt extends BackendRuntim
getMaterial(params: {
applicationId: string;
type: MenuType;
media_id: string;
mediaId: string;
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["getMaterial"]>>;
}

View File

@ -125,7 +125,7 @@ export type GeneralAspectDict<ED extends EntityDict, Cxt extends BackendRuntimeC
}, context: Cxt) => Promise<any>;
deleteConditionalMenu: (params: {
applicationId: string;
menuid: number;
menuId: number;
}, context: Cxt) => Promise<any>;
batchGetArticle: (params: {
applicationId: string;
@ -135,7 +135,7 @@ export type GeneralAspectDict<ED extends EntityDict, Cxt extends BackendRuntimeC
}, context: Cxt) => Promise<any>;
getArticle: (params: {
applicationId: string;
article_id: string;
articleId: string;
}, context: Cxt) => Promise<any>;
batchGetMaterialList: (params: {
applicationId: string;
@ -146,7 +146,7 @@ export type GeneralAspectDict<ED extends EntityDict, Cxt extends BackendRuntimeC
getMaterial: (params: {
applicationId: string;
type: MenuType;
media_id: string;
mediaId: string;
}, context: Cxt) => Promise<any>;
};
export default GeneralAspectDict;

View File

@ -3,6 +3,7 @@ import { AppType } from "../oak-app-domain/Application/Schema";
import { BackendRuntimeContext } from "../context/BackendRuntimeContext";
import { MediaType } from '../types/WeChat';
import { WebEnv } from 'oak-domain/lib/types/Environment';
import { File } from 'formidable';
export declare function getApplication<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
type: AppType;
domain: string;
@ -18,7 +19,7 @@ export declare function signatureJsSDK<ED extends EntityDict, Cxt extends Backen
}>;
export declare function uploadWechatMedia<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
file: any;
file: File;
type: MediaType;
isPermanent?: string;
description?: string;

View File

@ -66,6 +66,8 @@ exports.signatureJsSDK = signatureJsSDK;
async function uploadWechatMedia(params, // FormData表单提交 isPermanent 变成 'true' | 'false'
context) {
const { applicationId, file, type: mediaType, isPermanent, description, } = params;
const filename = file.originalFilename;
const filetype = file.mimetype;
const file2 = fs_1.default.createReadStream(file.filepath);
const [application] = await context.select('application', {
data: Projection_1.applicationProjection,
@ -84,6 +86,8 @@ context) {
const result = (await wechatInstance.createMaterial({
type: mediaType,
media: file2,
filename,
filetype,
description: description ? JSON.parse(description) : null,
}));
return {
@ -93,6 +97,8 @@ context) {
const result = (await wechatInstance.createTemporaryMaterial({
type: mediaType,
media: file2,
filename,
filetype,
}));
return {
mediaId: result.media_id,

View File

@ -17,7 +17,7 @@ export declare function createConditionalMenu<ED extends EntityDict, Cxt extends
}, context: Cxt): Promise<any>;
export declare function deleteConditionalMenu<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
menuid: number;
menuId: number;
}, context: Cxt): Promise<any>;
export declare function batchGetArticle<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
@ -27,7 +27,7 @@ export declare function batchGetArticle<ED extends EntityDict, Cxt extends Backe
}, context: Cxt): Promise<any>;
export declare function getArticle<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
article_id: string;
articleId: string;
}, context: Cxt): Promise<any>;
export declare function batchGetMaterialList<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
@ -38,5 +38,5 @@ export declare function batchGetMaterialList<ED extends EntityDict, Cxt extends
export declare function getMaterial<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(params: {
applicationId: string;
type: MenuType;
media_id: string;
mediaId: string;
}, context: Cxt): Promise<any>;

View File

@ -84,7 +84,7 @@ async function deleteConditionalMenu(params, context) {
appId = config2.appId;
appSecret = config2.appSecret;
const wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, type, appSecret);
const result = await wechatInstance.deleteConditionalMenu(params.menuid);
const result = await wechatInstance.deleteConditionalMenu(params.menuId);
return result;
}
exports.deleteConditionalMenu = deleteConditionalMenu;
@ -112,7 +112,9 @@ async function getArticle(params, context) {
appId = config2.appId;
appSecret = config2.appSecret;
const wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, type, appSecret);
const result = await wechatInstance.getArticle(params);
const result = await wechatInstance.getArticle({
articleId: params.articleId,
});
return result;
}
exports.getArticle = getArticle;
@ -140,7 +142,9 @@ async function getMaterial(params, context) {
appId = config2.appId;
appSecret = config2.appSecret;
const wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, type, appSecret);
const result = await wechatInstance.getMaterial(params);
const result = await wechatInstance.getMaterial({
mediaId: params.mediaId,
});
return result;
}
exports.getMaterial = getMaterial;

View File

@ -25,4 +25,4 @@ export default function render(props: WebComponentProps<EntityDict, 'extraFile',
}, {
onRemove: (file: UploadFile) => void;
addFileByWeb: (file: UploadFile) => void;
}>): JSX.Element;
}>): import("react/jsx-runtime").JSX.Element;

View File

@ -99,9 +99,13 @@ exports.default = OakComponent({
return false;
}
},
async getMaterialImg(media_id) {
async getMaterialImg(mediaId) {
const { applicationId } = this.props;
const imgFile = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type: 'image', media_id });
const imgFile = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type: 'image',
mediaId,
});
return new Promise((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);

View File

@ -4,7 +4,7 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps<
config: any;
menuIndex: number;
changeConfig: (config: any) => void;
changePublishState: (publish: "wait" | "success" | "fail") => void;
changePublishState: (publish: 'wait' | 'success' | 'fail') => void;
getErrorIndex: (errorIndex: number[]) => void;
createMenu: () => Promise<void>;
selectedBtn: number;

View File

@ -26,7 +26,8 @@ exports.default = OakComponent({
setConfig(index, content, currentIndex) {
const { config, changeConfig } = this.props;
if (typeof currentIndex === 'number') {
content.name = config.button[currentIndex].sub_button[index].name;
content.name =
config.button[currentIndex].sub_button[index].name;
config.button[currentIndex].sub_button[index] = content;
changeConfig(config);
}
@ -38,7 +39,10 @@ exports.default = OakComponent({
}
},
confirmName(menuName) {
if (Object.prototype.toString.call(menuName).slice(8, -1).toLowerCase() !== 'string') {
if (Object.prototype.toString
.call(menuName)
.slice(8, -1)
.toLowerCase() !== 'string') {
throw Error('param str type error ');
}
else if (!menuName) {
@ -47,13 +51,16 @@ exports.default = OakComponent({
else if (!/^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(menuName)) {
return '字符串中包含除中文、数字、英文以外的字符!';
}
else if (menuName.replace(/[\u4e00-\u9fa5]/g, "**").length > 8) {
else if (menuName.replace(/[\u4e00-\u9fa5]/g, '**').length > 8) {
return '字符串长度超过限制!';
}
return '';
},
confirmSubName(menuName) {
if (Object.prototype.toString.call(menuName).slice(8, -1).toLowerCase() !== 'string') {
if (Object.prototype.toString
.call(menuName)
.slice(8, -1)
.toLowerCase() !== 'string') {
throw Error('param str type error ');
}
else if (!menuName) {
@ -62,7 +69,7 @@ exports.default = OakComponent({
else if (!/^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(menuName)) {
return '字符串中包含除中文、数字、英文以外的字符!';
}
else if (menuName.replace(/[\u4e00-\u9fa5]/g, "**").length > 16) {
else if (menuName.replace(/[\u4e00-\u9fa5]/g, '**').length > 16) {
return '字符串长度超过限制!';
}
return '';
@ -87,35 +94,49 @@ exports.default = OakComponent({
deleteMenuContent(index, currentIndex) {
const { config, changeConfig } = this.props;
if (typeof currentIndex === 'number') {
config.button[currentIndex].sub_button[index] = { name: config.button[currentIndex].sub_button[index].name };
config.button[currentIndex].sub_button[index] = {
name: config.button[currentIndex].sub_button[index].name,
};
changeConfig(config);
}
else {
config.button[index] = { name: config.button[index].name, sub_button: [...config.button[index].sub_button] };
config.button[index] = {
name: config.button[index].name,
sub_button: [...config.button[index].sub_button],
};
changeConfig(config);
}
},
async getMaterialImgAndVoice(type, media_id) {
async getMaterialImgAndVoice(type, mediaId) {
const { applicationId } = this.props;
return new Promise((resolve, reject) => {
this.features.wechatMenu.getMaterial({ applicationId: applicationId, type, media_id })
.then(file => {
this.features.wechatMenu
.getMaterial({
applicationId: applicationId,
type,
mediaId,
})
.then((file) => {
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
resolve(e.target?.result);
};
})
.catch(error => {
.catch((error) => {
reject(error);
});
});
},
async getMaterialVideo(media_id) {
async getMaterialVideo(mediaId) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type: 'video', media_id });
const result = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type: 'video',
mediaId,
});
if (result && result.down_url) {
return { url: result.down_url, media_id };
return { url: result.down_url, media_id: mediaId };
}
},
decideMenuContentLabel(decidedMenuContent, type) {
@ -140,15 +161,18 @@ exports.default = OakComponent({
return '文字'; // 默认值
}
},
async getArticle(article_id) {
async getArticle(articleId) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getArticle({ applicationId: applicationId, article_id });
const result = await this.features.wechatMenu.getArticle({
applicationId: applicationId,
articleId,
});
if (result && result.news_item) {
const modifiedResult = await Promise.all(result.news_item.map(async (ele) => {
const coverUrl = await this.getMaterialImgAndVoice('image', ele.thumb_media_id);
return {
...ele,
coverUrl
coverUrl,
};
}));
return modifiedResult;
@ -160,13 +184,15 @@ exports.default = OakComponent({
arr.map((ele, index) => {
if (ele.sub_button && ele.sub_button.length > 0) {
ele.sub_button.map((ele, index2) => {
if (Object.keys(ele).length === 1 && ele.hasOwnProperty('name')) {
if (Object.keys(ele).length === 1 &&
ele.hasOwnProperty('name')) {
errorIndex.push((index + 1) * 10 + index2);
}
});
}
else {
if (Object.keys(ele).length === 2 && ele.hasOwnProperty('name')) {
if (Object.keys(ele).length === 2 &&
ele.hasOwnProperty('name')) {
console.log(index);
errorIndex.push(index);
}
@ -182,19 +208,20 @@ exports.default = OakComponent({
if (errorInfo) {
this.setMessage({
type: 'warning',
content: '菜单名称有误'
content: '菜单名称有误',
});
return;
}
if (errorUrlInfo) {
this.setMessage({
type: 'warning',
content: '公众号链接有误'
content: '公众号链接有误',
});
return;
}
const { applicationId, config, changeConfig, changePublishState, createMenu, menuType, changeMenuId } = this.props;
if (this.checkError(config.button).length === 0 && config.button.length > 0) {
const { applicationId, config, changeConfig, changePublishState, createMenu, menuType, changeMenuId, } = this.props;
if (this.checkError(config.button).length === 0 &&
config.button.length > 0) {
changeConfig(config);
const removeSubTypeAndContent = (obj) => {
const { subType, content, ...newObj } = obj;
@ -210,7 +237,10 @@ exports.default = OakComponent({
}
});
if (menuType === 'common') {
const result = await this.features.wechatMenu.createMenu({ applicationId: applicationId, menuConfig: { button: menuConfig } });
const result = await this.features.wechatMenu.createMenu({
applicationId: applicationId,
menuConfig: { button: menuConfig },
});
if (result.success) {
changePublishState('success');
}
@ -220,8 +250,14 @@ exports.default = OakComponent({
await createMenu();
}
else {
const button = { button: menuConfig, matchrule: config.matchrule };
const result = await this.features.wechatMenu.createConditionalMenu({ applicationId: applicationId, menuConfig: button });
const button = {
button: menuConfig,
matchrule: config.matchrule,
};
const result = await this.features.wechatMenu.createConditionalMenu({
applicationId: applicationId,
menuConfig: button,
});
if (result.success) {
changeMenuId(result.menuid);
changePublishState('success');
@ -236,14 +272,14 @@ exports.default = OakComponent({
if (config.button.length === 0) {
this.setMessage({
content: '请添加自定义菜单',
type: 'warning'
type: 'warning',
});
return;
}
if ((this.checkError(config.button).length > 0)) {
if (this.checkError(config.button).length > 0) {
this.setMessage({
content: '请添加菜单消息',
type: 'warning'
type: 'warning',
});
return;
}
@ -251,7 +287,7 @@ exports.default = OakComponent({
},
async deleteConditionalMenu() {
const { applicationId, deleteMenu, menuIndex, menuId, createMenu } = this.props;
const result = await this.features.wechatMenu.deleteConditionalMenu({ applicationId: applicationId, menuid: menuId });
const result = await this.features.wechatMenu.deleteConditionalMenu({ applicationId: applicationId, menuId: menuId });
if (result.success) {
deleteMenu();
await createMenu();
@ -259,9 +295,9 @@ exports.default = OakComponent({
else {
this.setMessage({
type: 'error',
content: result.errmsg
content: result.errmsg,
});
}
}
}
},
},
});

View File

@ -28,8 +28,8 @@ export default function Render(props: WebComponentProps<EntityDict, keyof Entity
toDown: (currentIndex: number, index: number) => void;
editMenuName: (index: number, name: string, currentIndex?: number) => void;
deleteMenuContent: (index: number, currentIndex?: number) => void;
getMaterialImgAndVoice: (type: string, media_id: string) => Promise<string>;
getMaterialVideo: (media_id: string) => void;
getMaterialImgAndVoice: (type: string, mediaId: string) => Promise<string>;
getMaterialVideo: (mediaId: string) => void;
decideMenuContentLabel: (obj: any, type: 'news' | 'image' | 'video' | 'voice' | 'text') => string;
getArticle: (article_id: string) => void;
createMenu: (errorInfo: string, errorUrlInfo: string) => void;

View File

@ -16,7 +16,7 @@ const selectArticle_1 = tslib_1.__importDefault(require("../selectArticle"));
const textClick_1 = tslib_1.__importDefault(require("../textClick"));
function Render(props) {
const { data, methods } = props;
const { config, menuIndex, selectedBtn, selectedSubBtn, currentIndex, changeIsPreview, getOpen, menuType, applicationId, menuId } = data;
const { config, menuIndex, selectedBtn, selectedSubBtn, currentIndex, changeIsPreview, getOpen, menuType, applicationId, menuId, } = data;
const { setConfig, confirmName, confirmSubName, editMenuName, deleteMenuContent, getMaterialImgAndVoice, getMaterialVideo, decideMenuContentLabel, getArticle, createMenu, deleteConditionalMenu, confirmUrl, } = methods;
const [msgType, setMsgType] = (0, react_1.useState)('sendMsg');
const [errorInfo, setErrorInfo] = (0, react_1.useState)('');
@ -35,10 +35,20 @@ function Render(props) {
setMenuContent(menuContent);
if (msgType === 'miniprogram') {
if (selectedBtn > 0) {
setConfig(selectedBtn - 1, { type: 'miniprogram', url: menuContent.url, pagepath: menuContent.pagepath, appid: menuContent.appid });
setConfig(selectedBtn - 1, {
type: 'miniprogram',
url: menuContent.url,
pagepath: menuContent.pagepath,
appid: menuContent.appid,
});
}
else {
setConfig(selectedSubBtn - 1, { type: 'miniprogram', url: menuContent.url, pagepath: menuContent.pagepath, appid: menuContent.appid }, currentIndex);
setConfig(selectedSubBtn - 1, {
type: 'miniprogram',
url: menuContent.url,
pagepath: menuContent.pagepath,
appid: menuContent.appid,
}, currentIndex);
}
}
};
@ -49,10 +59,20 @@ function Render(props) {
const getDecidedMenuContent = async (menuContent) => {
setDecidedMenuContent(menuContent);
if (selectedBtn > 0) {
setConfig(selectedBtn - 1, { type: 'click', key: await (0, uuid_1.generateNewIdAsync)(), subType: 'text', content: menuContent });
setConfig(selectedBtn - 1, {
type: 'click',
key: await (0, uuid_1.generateNewIdAsync)(),
subType: 'text',
content: menuContent,
});
}
else {
setConfig(selectedSubBtn - 1, { type: 'click', key: await (0, uuid_1.generateNewIdAsync)(), subType: 'text', content: menuContent }, currentIndex);
setConfig(selectedSubBtn - 1, {
type: 'click',
key: await (0, uuid_1.generateNewIdAsync)(),
subType: 'text',
content: menuContent,
}, currentIndex);
}
};
(0, react_1.useEffect)(() => {
@ -65,13 +85,18 @@ function Render(props) {
(0, react_1.useEffect)(() => {
const fetchData = async (id, type) => {
if (type === 'news') {
setDecidedMenuContent({ content: { news_item: await getArticle(id) } });
setDecidedMenuContent({
content: { news_item: await getArticle(id) },
});
}
if (type === 'video') {
setDecidedMenuContent(await getMaterialVideo(id));
}
if (type === 'image' || type === 'voice') {
setDecidedMenuContent({ url: await getMaterialImgAndVoice(type, id), media_id: id });
setDecidedMenuContent({
url: await getMaterialImgAndVoice(type, id),
media_id: id,
});
}
};
if (selectedBtn !== 0) {
@ -106,7 +131,7 @@ function Render(props) {
setMenuContent({
appid: menuConfig.appid,
url: menuConfig.url,
pagepath: menuConfig.pagepath
pagepath: menuConfig.pagepath,
});
}
else if (menuConfig?.type === 'view') {
@ -125,13 +150,18 @@ function Render(props) {
(0, react_1.useEffect)(() => {
const fetchData = async (id, type) => {
if (type === 'news') {
setDecidedMenuContent({ content: { news_item: await getArticle(id) } });
setDecidedMenuContent({
content: { news_item: await getArticle(id) },
});
}
if (type === 'video') {
setDecidedMenuContent(await getMaterialVideo(id));
}
if (type === 'image' || type === 'voice') {
setDecidedMenuContent({ url: await getMaterialImgAndVoice(type, id), media_id: id });
setDecidedMenuContent({
url: await getMaterialImgAndVoice(type, id),
media_id: id,
});
}
};
if (selectedSubBtn !== 0) {
@ -166,7 +196,7 @@ function Render(props) {
setMenuContent({
appid: subMenuConfig.appid,
url: subMenuConfig.url,
pagepath: subMenuConfig.pagepath
pagepath: subMenuConfig.pagepath,
});
}
else if (subMenuConfig?.type === 'view') {
@ -192,7 +222,10 @@ function Render(props) {
}
}
}, [url]);
return ((0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.container, children: config && config.button && config.button.length > 0 && (selectedBtn !== 0 || selectedSubBtn !== 0) ? ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.upsertMenu, children: [(0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.content, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.title, children: selectedSubBtn !== 0 ? '子菜单信息' : '菜单信息' }), (0, jsx_runtime_1.jsx)("div", { style: { marginBottom: 32 }, children: (0, jsx_runtime_1.jsx)(antd_1.Form.Item, { label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: "\u540D\u79F0" }), colon: false, help: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { children: `仅支持中英文和数字,字数不超过${selectedSubBtn !== 0 ? 8 : 4}个汉字或${selectedSubBtn !== 0 ? 16 : 8}个字母。` }), errorInfo && (0, jsx_runtime_1.jsx)("div", { style: { color: '#fa5151' }, children: errorInfo })] }), children: (0, jsx_runtime_1.jsx)(antd_1.Input, { style: { width: 340 }, onChange: (val) => {
return ((0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.container, children: config &&
config.button &&
config.button.length > 0 &&
(selectedBtn !== 0 || selectedSubBtn !== 0) ? ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.upsertMenu, children: [(0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.content, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.title, children: selectedSubBtn !== 0 ? '子菜单信息' : '菜单信息' }), (0, jsx_runtime_1.jsx)("div", { style: { marginBottom: 32 }, children: (0, jsx_runtime_1.jsx)(antd_1.Form.Item, { label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: "\u540D\u79F0" }), colon: false, help: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { children: `仅支持中英文和数字,字数不超过${selectedSubBtn !== 0 ? 8 : 4}个汉字或${selectedSubBtn !== 0 ? 16 : 8}个字母。` }), errorInfo && ((0, jsx_runtime_1.jsx)("div", { style: { color: '#fa5151' }, children: errorInfo }))] }), children: (0, jsx_runtime_1.jsx)(antd_1.Input, { style: { width: 340 }, onChange: (val) => {
setMenuName(val.target.value);
if (selectedSubBtn !== 0) {
setErrorInfo(confirmSubName(val.target.value));
@ -206,8 +239,11 @@ function Render(props) {
editMenuName(selectedBtn - 1, val.target.value);
}
}
}, status: errorInfo ? 'error' : '', value: menuName }) }) }), config.button[currentIndex]?.sub_button?.length === 0 && selectedSubBtn === 0
|| selectedSubBtn > 0 ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(antd_1.Form.Item, { colon: false, label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: "\u6D88\u606F\u7C7B\u578B" }), children: (0, jsx_runtime_1.jsxs)(antd_1.Radio.Group, { value: msgType, onChange: (val) => setMsgType(val.target.value), children: [(0, jsx_runtime_1.jsx)(antd_1.Radio, { value: 'sendMsg', children: "\u53D1\u9001\u6D88\u606F" }), (0, jsx_runtime_1.jsx)(antd_1.Radio, { value: 'view', children: "\u8DF3\u8F6C\u9875\u9762" }), (0, jsx_runtime_1.jsx)(antd_1.Radio, { value: 'miniprogram', children: "\u8DF3\u8F6C\u5C0F\u7A0B\u5E8F" })] }) }), msgType === 'sendMsg' ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(antd_1.Form.Item, { colon: false, label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: decideMenuContentLabel(decidedMenuContent, type) }), children: [!decidedMenuContent && type !== 'text' ? (0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.menuContent, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.item, onClick: () => {
}, status: errorInfo ? 'error' : '', value: menuName }) }) }), (config.button[currentIndex]?.sub_button?.length ===
0 &&
selectedSubBtn === 0) ||
selectedSubBtn > 0 ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(antd_1.Form.Item, { colon: false, label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: "\u6D88\u606F\u7C7B\u578B" }), children: (0, jsx_runtime_1.jsxs)(antd_1.Radio.Group, { value: msgType, onChange: (val) => setMsgType(val.target.value), children: [(0, jsx_runtime_1.jsx)(antd_1.Radio, { value: 'sendMsg', children: "\u53D1\u9001\u6D88\u606F" }), (0, jsx_runtime_1.jsx)(antd_1.Radio, { value: 'view', children: "\u8DF3\u8F6C\u9875\u9762" }), (0, jsx_runtime_1.jsx)(antd_1.Radio, { value: 'miniprogram', children: "\u8DF3\u8F6C\u5C0F\u7A0B\u5E8F" })] }) }), msgType === 'sendMsg' ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(antd_1.Form.Item, { colon: false, label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: decideMenuContentLabel(decidedMenuContent, type) }), children: [!decidedMenuContent &&
type !== 'text' ? ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.menuContent, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.item, onClick: () => {
setOpen(true);
getOpen(true);
setType('news');
@ -225,152 +261,213 @@ function Render(props) {
setOpen(true);
getOpen(true);
setType('video');
}, children: "\u89C6\u9891" })] })
: type === 'image' ?
(0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.coverImage, children: [(0, jsx_runtime_1.jsx)("img", { className: web_module_less_1.default.img, src: decidedMenuContent.url }), (0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.buttonGroup, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该图片吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
}
;
},
});
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: (0, jsx_runtime_1.jsx)(icons_1.SwapOutlined, {}) })] })] })
: type === 'voice' ?
(0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.fileCover, children: [(0, jsx_runtime_1.jsxs)("a", { href: decidedMenuContent.url, download: true, style: { color: '#1677FF', cursor: 'pointer' }, children: [(0, jsx_runtime_1.jsx)(icons_1.DownloadOutlined, {}), decidedMenuContent.media_id] }), (0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.buttonGroup, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该音频吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
}
;
},
});
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: (0, jsx_runtime_1.jsx)(icons_1.SwapOutlined, {}) })] })] })
: type === 'video' ?
(0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.fileCover, children: [(0, jsx_runtime_1.jsxs)("a", { href: decidedMenuContent.url, download: true, style: { color: '#1677FF', cursor: 'pointer' }, children: [(0, jsx_runtime_1.jsx)(icons_1.DownloadOutlined, {}), decidedMenuContent.media_id] }), (0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.buttonGroup, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该视频吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
}
;
},
});
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: (0, jsx_runtime_1.jsx)(icons_1.SwapOutlined, {}) })] })] })
: type === 'news' ?
(0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.news, children: [(0, jsx_runtime_1.jsx)(showNews_1.default, { news: decidedMenuContent?.content?.news_item, oakAutoUnmount: false }), (0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.buttonGroup, style: { height: '100%' }, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该图文信息吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
}
;
},
});
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: (0, jsx_runtime_1.jsx)(icons_1.SwapOutlined, {}) })] })] })
: null, type === 'text' &&
(0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.editor, children: [(0, jsx_runtime_1.jsx)(textClick_1.default, { oakAutoUnmount: true, value: decidedMenuContent, getDecidedMenuContent: getDecidedMenuContent }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonGroup, style: { height: 36, position: 'absolute', right: -50 }, children: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
}, children: "\u89C6\u9891" })] })) : type === 'image' ? ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.coverImage, children: [(0, jsx_runtime_1.jsx)("img", { className: web_module_less_1.default.img, src: decidedMenuContent.url }), (0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.buttonGroup, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该文字吗?',
title: '确定删除该图片吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setType('news');
setDecidedMenuContent(null);
if (selectedBtn > 0) {
deleteMenuContent(selectedBtn - 1);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn - 1, currentIndex);
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }) })] })] }), (0, jsx_runtime_1.jsx)(antd_1.Modal, { open: open, footer: (0, jsx_runtime_1.jsxs)(antd_1.Space, { children: [(0, jsx_runtime_1.jsx)(antd_1.Button, { type: 'primary', disabled: !menuContent, onClick: () => {
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: (0, jsx_runtime_1.jsx)(icons_1.SwapOutlined, {}) })] })] })) : type === 'voice' ? ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.fileCover, children: [(0, jsx_runtime_1.jsxs)("a", { href: decidedMenuContent.url, download: true, style: {
color: '#1677FF',
cursor: 'pointer',
}, children: [(0, jsx_runtime_1.jsx)(icons_1.DownloadOutlined, {}), decidedMenuContent.media_id] }), (0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.buttonGroup, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该音频吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: (0, jsx_runtime_1.jsx)(icons_1.SwapOutlined, {}) })] })] })) : type === 'video' ? ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.fileCover, children: [(0, jsx_runtime_1.jsxs)("a", { href: decidedMenuContent.url, download: true, style: {
color: '#1677FF',
cursor: 'pointer',
}, children: [(0, jsx_runtime_1.jsx)(icons_1.DownloadOutlined, {}), decidedMenuContent.media_id] }), (0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.buttonGroup, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该视频吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: (0, jsx_runtime_1.jsx)(icons_1.SwapOutlined, {}) })] })] })) : type === 'news' ? ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.news, children: [(0, jsx_runtime_1.jsx)(showNews_1.default, { news: decidedMenuContent
?.content
?.news_item, oakAutoUnmount: false }), (0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.buttonGroup, style: {
height: '100%',
}, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该图文信息吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setDecidedMenuContent(null);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
setOpen(true);
getOpen(true);
}, children: (0, jsx_runtime_1.jsx)(icons_1.SwapOutlined, {}) })] })] })) : null, type === 'text' && ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.editor, children: [(0, jsx_runtime_1.jsx)(textClick_1.default, { oakAutoUnmount: true, value: decidedMenuContent, getDecidedMenuContent: getDecidedMenuContent }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonGroup, style: {
height: 36,
position: 'absolute',
right: -50,
}, children: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.buttonItem, onClick: () => {
const modal = confirm({
title: '确定删除该文字吗?',
content: '删除后不可恢复',
okText: '确定',
cancelText: '取消',
onOk: async (e) => {
modal.destroy();
setType('news');
setDecidedMenuContent(null);
if (selectedBtn >
0) {
deleteMenuContent(selectedBtn -
1);
}
else {
deleteMenuContent(selectedSubBtn -
1, currentIndex);
}
},
});
}, children: (0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}) }) })] }))] }), (0, jsx_runtime_1.jsx)(antd_1.Modal, { open: open, footer: (0, jsx_runtime_1.jsxs)(antd_1.Space, { children: [(0, jsx_runtime_1.jsx)(antd_1.Button, { type: 'primary', disabled: !menuContent, onClick: () => {
setOpen(false);
getOpen(false);
setDecidedMenuContent(menuContent);
if (selectedBtn > 0) {
if (type !== 'news') {
if (type === 'image') {
setConfig(selectedBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'image' });
if (type !==
'news') {
if (type ===
'image') {
setConfig(selectedBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'image',
});
}
if (type === 'voice') {
setConfig(selectedBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'voice' });
if (type ===
'voice') {
setConfig(selectedBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'voice',
});
}
if (type === 'video') {
setConfig(selectedBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'video' });
if (type ===
'video') {
setConfig(selectedBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'video',
});
}
}
else {
setConfig(selectedBtn - 1, { type: 'article_id', article_id: menuContent.article_id });
setConfig(selectedBtn -
1, {
type: 'article_id',
article_id: menuContent.article_id,
});
}
}
else {
if (type !== 'news') {
if (type === 'image') {
setConfig(selectedSubBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'image' }, currentIndex);
if (type !==
'news') {
if (type ===
'image') {
setConfig(selectedSubBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'image',
}, currentIndex);
}
if (type === 'voice') {
setConfig(selectedSubBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'voice' }, currentIndex);
if (type ===
'voice') {
setConfig(selectedSubBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'voice',
}, currentIndex);
}
if (type === 'video') {
setConfig(selectedSubBtn - 1, { type: 'media_id', media_id: menuContent.media_id, subType: 'video' }, currentIndex);
if (type ===
'video') {
setConfig(selectedSubBtn -
1, {
type: 'media_id',
media_id: menuContent.media_id,
subType: 'video',
}, currentIndex);
}
}
else {
setConfig(selectedSubBtn - 1, { type: 'article_id', article_id: menuContent.article_id }, currentIndex);
setConfig(selectedSubBtn -
1, {
type: 'article_id',
article_id: menuContent.article_id,
}, currentIndex);
}
}
}, children: "\u786E\u5B9A" }), (0, jsx_runtime_1.jsx)(antd_1.Button, { type: 'default', onClick: () => {
@ -381,15 +478,29 @@ function Render(props) {
setOpen(false);
getOpen(false);
setMenuContent(null);
}, destroyOnClose: true, width: 960, children: (0, jsx_runtime_1.jsx)(wechatMaterialLibrary_1.default, { oakAutoUnmount: true, type: type, getMenuContent: getMenuContent, applicationId: applicationId }) })] })) : msgType === 'view' ? ((0, jsx_runtime_1.jsxs)(antd_1.Form.Item, { colon: false, label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: "\u7F51\u9875\u94FE\u63A5" }), help: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: errorUrlInfo && (0, jsx_runtime_1.jsx)("div", { style: { color: '#fa5151' }, children: errorUrlInfo }) }), children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: '\u516C\u4F17\u53F7\u94FE\u63A5:\u8BF7\u4EE5https://\u6216http://\u5F00\u5934', style: { width: 340 }, value: url, onChange: (val) => {
}, destroyOnClose: true, width: 960, children: (0, jsx_runtime_1.jsx)(wechatMaterialLibrary_1.default, { oakAutoUnmount: true, type: type, getMenuContent: getMenuContent, applicationId: applicationId }) })] })) : msgType === 'view' ? ((0, jsx_runtime_1.jsxs)(antd_1.Form.Item, { colon: false, label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: "\u7F51\u9875\u94FE\u63A5" }), help: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: errorUrlInfo && ((0, jsx_runtime_1.jsx)("div", { style: {
color: '#fa5151',
}, children: errorUrlInfo })) }), children: [(0, jsx_runtime_1.jsxs)("div", { style: {
display: 'flex',
flexDirection: 'column',
}, children: [(0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: "\u516C\u4F17\u53F7\u94FE\u63A5:\u8BF7\u4EE5https://\u6216http://\u5F00\u5934", style: { width: 340 }, value: url, onChange: (val) => {
setUrl(val.target.value);
setErrorUrlInfo(confirmUrl(val.target.value));
}, status: errorUrlInfo ? 'error' : '' }), (0, jsx_runtime_1.jsx)("a", { style: { padding: '10px 0' }, onClick: () => { setOpen(true); getOpen(true); }, children: "\u9009\u62E9\u56FE\u6587\u94FE\u63A5" })] }), (0, jsx_runtime_1.jsx)(antd_1.Modal, { open: open, footer: null, title: '选择图文链接', onCancel: () => { setOpen(false); getOpen(false); }, width: 600, children: (0, jsx_runtime_1.jsx)(selectArticle_1.default, { oakAutoUnmount: true, changeOpen: changeOpen, getUrl: getUrl, applicationId: applicationId }) })] })) : ((0, jsx_runtime_1.jsxs)(antd_1.Form.Item, { colon: false, label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: "\u5C0F\u7A0B\u5E8F" }), children: [(0, jsx_runtime_1.jsx)(antd_1.Button, { onClick: () => {
}, status: errorUrlInfo ? 'error' : '' }), (0, jsx_runtime_1.jsx)("a", { style: { padding: '10px 0' }, onClick: () => {
setOpen(true);
getOpen(true);
}, children: "\u9009\u62E9\u56FE\u6587\u94FE\u63A5" })] }), (0, jsx_runtime_1.jsx)(antd_1.Modal, { open: open, footer: null, title: '选择图文链接', onCancel: () => {
setOpen(false);
getOpen(false);
}, width: 600, children: (0, jsx_runtime_1.jsx)(selectArticle_1.default, { oakAutoUnmount: true, changeOpen: changeOpen, getUrl: getUrl, applicationId: applicationId }) })] })) : ((0, jsx_runtime_1.jsxs)(antd_1.Form.Item, { colon: false, label: (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.label, children: "\u5C0F\u7A0B\u5E8F" }), children: [(0, jsx_runtime_1.jsx)(antd_1.Button, { onClick: () => {
setOpen(true);
getOpen(true);
}, children: "\u9009\u62E9\u5C0F\u7A0B\u5E8F" }), menuContent && menuContent.appid && (0, jsx_runtime_1.jsx)("div", { children: menuContent.appid }), (0, jsx_runtime_1.jsx)(antd_1.Modal, { title: '添加小程序', open: open, footer: null, onCancel: () => { setOpen(false); getOpen(false); }, children: (0, jsx_runtime_1.jsx)(selectMiniprogram_1.default, { oakAutoUnmount: true, getMenuContent: getMenuContent, changeOpen: changeOpen }) })] }))] })) : (null)] }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.actionBar, children: (0, jsx_runtime_1.jsxs)(antd_1.Space, { children: [(0, jsx_runtime_1.jsxs)(antd_1.Button, { onClick: () => changeIsPreview(true), children: [(0, jsx_runtime_1.jsx)(icons_1.EyeOutlined, {}), "\u9884\u89C8"] }), (0, jsx_runtime_1.jsxs)(antd_1.Button, { type: 'primary', onClick: async () => {
}, children: "\u9009\u62E9\u5C0F\u7A0B\u5E8F" }), menuContent && menuContent.appid && ((0, jsx_runtime_1.jsx)("div", { children: menuContent.appid })), (0, jsx_runtime_1.jsx)(antd_1.Modal, { title: '添加小程序', open: open, footer: null, onCancel: () => {
setOpen(false);
getOpen(false);
}, children: (0, jsx_runtime_1.jsx)(selectMiniprogram_1.default, { oakAutoUnmount: true, getMenuContent: getMenuContent, changeOpen: changeOpen }) })] }))] })) : null] }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.actionBar, children: (0, jsx_runtime_1.jsxs)(antd_1.Space, { children: [(0, jsx_runtime_1.jsxs)(antd_1.Button, { onClick: () => changeIsPreview(true), children: [(0, jsx_runtime_1.jsx)(icons_1.EyeOutlined, {}), "\u9884\u89C8"] }), (0, jsx_runtime_1.jsxs)(antd_1.Button, { type: "primary", onClick: async () => {
createMenu(errorInfo, errorUrlInfo);
}, children: [(0, jsx_runtime_1.jsx)(icons_1.CheckOutlined, {}), "\u53D1\u5E03"] }), menuType === 'conditional' && config && menuId && (0, jsx_runtime_1.jsxs)(antd_1.Button, { type: 'primary', danger: true, onClick: () => {
}, children: [(0, jsx_runtime_1.jsx)(icons_1.CheckOutlined, {}), "\u53D1\u5E03"] }), menuType === 'conditional' && config && menuId && ((0, jsx_runtime_1.jsxs)(antd_1.Button, { type: "primary", danger: true, onClick: () => {
const modal = confirm({
title: '确定删除该个性化菜单吗?',
content: '删除后不可恢复',
@ -400,7 +511,7 @@ function Render(props) {
modal.destroy();
},
});
}, children: [(0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}), "\u5220\u9664"] })] }) })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.empty, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.content, children: "\u4F60\u672A\u6DFB\u52A0\u81EA\u5B9A\u4E49\u83DC\u5355\uFF0C\u70B9\u51FB\u5DE6\u4FA7\u6DFB\u52A0\u83DC\u5355\u4E3A\u516C\u4F17\u53F7\u521B\u5EFA\u83DC\u5355\u680F\u3002" }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.actionBar, children: (0, jsx_runtime_1.jsxs)(antd_1.Space, { children: [(0, jsx_runtime_1.jsxs)(antd_1.Button, { onClick: () => changeIsPreview(true), children: [(0, jsx_runtime_1.jsx)(icons_1.EyeOutlined, {}), "\u9884\u89C8"] }), (0, jsx_runtime_1.jsxs)(antd_1.Button, { type: 'primary', onClick: async () => {
}, children: [(0, jsx_runtime_1.jsx)(icons_1.DeleteOutlined, {}), "\u5220\u9664"] }))] }) })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: web_module_less_1.default.empty, children: [(0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.content, children: "\u4F60\u672A\u6DFB\u52A0\u81EA\u5B9A\u4E49\u83DC\u5355\uFF0C\u70B9\u51FB\u5DE6\u4FA7\u6DFB\u52A0\u83DC\u5355\u4E3A\u516C\u4F17\u53F7\u521B\u5EFA\u83DC\u5355\u680F\u3002" }), (0, jsx_runtime_1.jsx)("div", { className: web_module_less_1.default.actionBar, children: (0, jsx_runtime_1.jsxs)(antd_1.Space, { children: [(0, jsx_runtime_1.jsxs)(antd_1.Button, { onClick: () => changeIsPreview(true), children: [(0, jsx_runtime_1.jsx)(icons_1.EyeOutlined, {}), "\u9884\u89C8"] }), (0, jsx_runtime_1.jsxs)(antd_1.Button, { type: "primary", onClick: async () => {
createMenu(errorInfo, errorUrlInfo);
}, children: [(0, jsx_runtime_1.jsx)(icons_1.CheckOutlined, {}), "\u53D1\u5E03"] })] }) })] })) }));
}

View File

@ -9,9 +9,13 @@ exports.default = OakComponent({
},
data: {},
methods: {
async getMaterialImgAndVoice(type, media_id) {
async getMaterialImgAndVoice(type, mediaId) {
const { applicationId } = this.props;
const imgFile = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type, media_id });
const imgFile = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type,
mediaId,
});
return new Promise((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);
@ -20,26 +24,33 @@ exports.default = OakComponent({
};
});
},
async getArticle(article_id) {
async getArticle(articleId) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getArticle({ applicationId: applicationId, article_id });
const result = await this.features.wechatMenu.getArticle({
applicationId: applicationId,
articleId,
});
if (result && result.news_item) {
const modifiedResult = await Promise.all(result.news_item.map(async (ele) => {
const coverUrl = await this.getMaterialImgAndVoice('image', ele.thumb_media_id);
return {
...ele,
coverUrl
coverUrl,
};
}));
return modifiedResult;
}
},
async getMaterialVideo(media_id) {
async getMaterialVideo(mediaId) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type: 'video', media_id });
const result = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type: 'video',
mediaId,
});
if (result && result.down_url) {
return { url: result.down_url, media_id };
return { url: result.down_url, media_id: mediaId };
}
},
}
},
});

View File

@ -7,7 +7,7 @@ export default function Render(props: WebComponentProps<EntityDict, keyof Entity
}, {
getMaterialImgAndVoice: (type: 'image' | 'voice', media_id: string) => Promise<string>;
getArticle: (article_id: string) => Promise<any[]>;
getMaterialVideo: (media_id: string) => {
getMaterialVideo: (mediaId: string) => {
url: string;
media_id: string;
};

View File

@ -13,27 +13,32 @@ exports.default = OakComponent({
if (applicationId) {
this.getArticleList(1);
}
}
},
},
methods: {
async getArticleList(page) {
const { applicationId } = this.props;
const offset = (page - 1) * 10;
const result = await this.features.wechatMenu.batchGetArticle({ applicationId: applicationId, offset, count: 10, noContent: 0 });
const result = await this.features.wechatMenu.batchGetArticle({
applicationId: applicationId,
offset,
count: 10,
noContent: 0,
});
const modifiedResult = await Promise.all(result.item.map(async (ele) => {
const news_item = await Promise.all(ele.content.news_item.map(async (ele2) => {
const coverUrl = await this.getMaterialImg(ele2.thumb_media_id);
return {
...ele2,
coverUrl
coverUrl,
};
}));
return {
...ele,
content: {
...ele.content,
news_item
}
news_item,
},
};
}));
this.setState({
@ -41,9 +46,13 @@ exports.default = OakComponent({
total: result.total_count,
});
},
async getMaterialImg(media_id) {
async getMaterialImg(mediaId) {
const { applicationId } = this.props;
const imgFile = await this.features.wechatMenu.getMaterial({ applicationId: applicationId, type: 'image', media_id });
const imgFile = await this.features.wechatMenu.getMaterial({
applicationId: applicationId,
type: 'image',
mediaId,
});
return new Promise((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);
@ -51,6 +60,6 @@ exports.default = OakComponent({
resolve(e.target?.result);
};
});
}
}
},
},
});

View File

@ -27,7 +27,7 @@ export declare class WechatMenu<ED extends EntityDict, Cxt extends BackendRuntim
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["createConditionalMenu"]>>;
deleteConditionalMenu(params: {
applicationId: string;
menuid: number;
menuId: number;
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["deleteConditionalMenu"]>>;
batchGetArticle(params: {
applicationId: string;
@ -37,7 +37,7 @@ export declare class WechatMenu<ED extends EntityDict, Cxt extends BackendRuntim
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["batchGetArticle"]>>;
getArticle(params: {
applicationId: string;
article_id: string;
articleId: string;
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["getArticle"]>>;
createMaterial(params: {
applicationId: string;
@ -55,6 +55,6 @@ export declare class WechatMenu<ED extends EntityDict, Cxt extends BackendRuntim
getMaterial(params: {
applicationId: string;
type: MenuType;
media_id: string;
mediaId: string;
}): Promise<ReturnType<(AD & CommonAspectDict<ED, Cxt>)["getMaterial"]>>;
}

View File

@ -50,6 +50,7 @@
"@babel/preset-typescript": "^7.12.13",
"@types/assert": "^1.5.6",
"@types/cross-spawn": "^6.0.2",
"@types/formidable": "^3.4.3",
"@types/fs-extra": "^9.0.13",
"@types/lodash": "^4.14.168",
"@types/mocha": "^8.2.0",

View File

@ -167,74 +167,74 @@ export type GeneralAspectDict<
newPassword: string;
},
context: Cxt
) => Promise<{ result: string, times?: number }>;
) => Promise<{ result: string; times?: number }>;
uploadWechatMedia: (
params: any,
context: Cxt
) => Promise<{ mediaId: string }>;
getCurrentMenu: (
params: {
applicationId: string,
applicationId: string;
},
context: Cxt
) => Promise<any>;
) => Promise<any>;
getMenu: (
params: {
applicationId: string,
applicationId: string;
},
context: Cxt
) => Promise<any>;
createMenu: (
params: {
applicationId: string,
menuConfig: any
applicationId: string;
menuConfig: any;
},
context: Cxt
) => Promise<any>;
) => Promise<any>;
createConditionalMenu: (
params: {
applicationId: string,
menuConfig: any
applicationId: string;
menuConfig: any;
},
context: Cxt
) => Promise<any>;
) => Promise<any>;
deleteConditionalMenu: (
params: {
applicationId: string,
menuid: number,
applicationId: string;
menuId: number;
},
context: Cxt
) => Promise<any>;
) => Promise<any>;
batchGetArticle: (
params: {
applicationId: string,
applicationId: string;
offset?: number;
count: number;
noContent?: 0 | 1;
},
context: Cxt
) => Promise<any>;
) => Promise<any>;
getArticle: (
params: {
applicationId: string,
article_id: string
applicationId: string;
articleId: string;
},
context: Cxt
) => Promise<any>;
) => Promise<any>;
batchGetMaterialList: (
params: {
applicationId: string,
type: MenuType,
applicationId: string;
type: MenuType;
offset?: number;
count: number;
},
context: Cxt
) => Promise<any>;
) => Promise<any>;
getMaterial: (
params: {
applicationId: string,
type: MenuType,
media_id: string,
applicationId: string;
type: MenuType;
mediaId: string;
},
context: Cxt
) => Promise<any>;

View File

@ -3,7 +3,7 @@ import { EntityDict } from "../oak-app-domain";
import { AppType, WechatPublicConfig } from "../oak-app-domain/Application/Schema";
import { BackendRuntimeContext } from "../context/BackendRuntimeContext";
import { applicationProjection } from '../types/Projection';
import { MediaType, MediaVideoDescription } from '../types/WeChat';
import { MediaType } from '../types/WeChat';
import {
WebEnv,
} from 'oak-domain/lib/types/Environment';
@ -12,6 +12,7 @@ import {
WechatSDK,
} from 'oak-external-sdk';
import fs from 'fs';
import { File } from 'formidable';
export async function getApplication<
ED extends EntityDict,
@ -113,13 +114,13 @@ export async function uploadWechatMedia<
>(
params: {
applicationId: string;
file: any;
file: File;
type: MediaType;
isPermanent?: string; //上传临时素材 或永久素材
description?: string;
isPermanent?: string; // 上传临时素材或永久素材 默认上传临时
description?: string; // { title: string; introduction: string }
}, // FormData表单提交 isPermanent 变成 'true' | 'false'
context: Cxt
): Promise<{ mediaId: string; }> {
): Promise<{ mediaId: string }> {
const {
applicationId,
file,
@ -127,7 +128,9 @@ export async function uploadWechatMedia<
isPermanent,
description,
} = params;
const file2 = fs.createReadStream(file.filepath)
const filename = file.originalFilename!;
const filetype = file.mimetype!;
const file2 = fs.createReadStream(file.filepath);
const [application] = await context.select(
'application',
@ -155,7 +158,9 @@ export async function uploadWechatMedia<
if (isPermanent === 'true') {
const result = (await wechatInstance.createMaterial({
type: mediaType,
media: file2 as any,
media: file2,
filename,
filetype,
description: description ? JSON.parse(description) : null,
})) as {
media_id: string;
@ -169,7 +174,9 @@ export async function uploadWechatMedia<
const result = (await wechatInstance.createTemporaryMaterial({
type: mediaType,
media: file2 as any,
media: file2,
filename,
filetype,
})) as {
media_id: string;
createdAt: Number;
@ -179,5 +186,4 @@ export async function uploadWechatMedia<
return {
mediaId: result.media_id,
};
}

View File

@ -163,15 +163,15 @@ export async function deleteConditionalMenu<
Cxt extends BackendRuntimeContext<ED>
>(
params: {
applicationId: string,
menuid: number,
applicationId: string;
menuId: number;
},
context: Cxt,
context: Cxt
): Promise<any> {
const application = await getWechatPublicConfig<
ED,
Cxt
>(params.applicationId, context);
const application = await getWechatPublicConfig<ED, Cxt>(
params.applicationId,
context
);
assert(application);
const { type, config, systemId } = application!;
assert(type === 'wechatPublic');
@ -184,7 +184,7 @@ export async function deleteConditionalMenu<
type!,
appSecret!
) as WechatPublicInstance;
const result = await wechatInstance.deleteConditionalMenu(params.menuid);
const result = await wechatInstance.deleteConditionalMenu(params.menuId);
return result;
}
@ -226,7 +226,7 @@ export async function getArticle<
>(
params: {
applicationId: string,
article_id: string
articleId: string
},
context: Cxt,
): Promise<any> {
@ -246,7 +246,9 @@ export async function getArticle<
type!,
appSecret!
) as WechatPublicInstance;
const result = await wechatInstance.getArticle(params);
const result = await wechatInstance.getArticle({
articleId: params.articleId,
});
return result;
}
@ -291,7 +293,7 @@ export async function getMaterial<
params: {
applicationId: string,
type: MenuType,
media_id: string,
mediaId: string,
},
context: Cxt,
): Promise<any> {
@ -311,7 +313,9 @@ export async function getMaterial<
type!,
appSecret!
) as WechatPublicInstance;
const result = await wechatInstance.getMaterial(params);
const result = await wechatInstance.getMaterial({
mediaId: params.mediaId,
});
return result;
}

View File

@ -99,9 +99,13 @@ export default OakComponent({
return false;
}
},
async getMaterialImg(media_id: string) {
async getMaterialImg(mediaId: string) {
const { applicationId } = this.props
const imgFile = await this.features.wechatMenu.getMaterial({ applicationId: applicationId!, type: 'image', media_id });
const imgFile = await this.features.wechatMenu.getMaterial({
applicationId: applicationId!,
type: 'image',
mediaId,
});
return new Promise<string | ArrayBuffer | PromiseLike<string | ArrayBuffer | null> | null | undefined>((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);

View File

@ -6,7 +6,8 @@ export default OakComponent({
config: null as any,
menuIndex: 0,
changeConfig: (config: any) => undefined as void,
changePublishState: (publish: "wait" | "success" | "fail") => undefined as void,
changePublishState: (publish: 'wait' | 'success' | 'fail') =>
undefined as void,
getErrorIndex: (errorIndex: number[]) => undefined as void,
createMenu: async () => undefined as void,
selectedBtn: 0,
@ -20,14 +21,13 @@ export default OakComponent({
deleteMenu: () => undefined as void,
menuId: null as unknown as number,
},
data: {
},
data: {},
methods: {
setConfig(index: number, content: any, currentIndex?: number) {
const { config, changeConfig } = this.props;
if (typeof currentIndex === 'number') {
content.name = config!.button![currentIndex].sub_button[index].name;
content.name =
config!.button![currentIndex].sub_button[index].name;
config!.button![currentIndex].sub_button[index] = content;
changeConfig!(config);
} else {
@ -38,32 +38,42 @@ export default OakComponent({
}
},
confirmName(menuName: string) {
if (Object.prototype.toString.call(menuName).slice(8, -1).toLowerCase() !== 'string') {
if (
Object.prototype.toString
.call(menuName)
.slice(8, -1)
.toLowerCase() !== 'string'
) {
throw Error('param str type error ');
} else if (!menuName) {
return '请输入菜单名称';
} else if (!/^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(menuName)) {
return '字符串中包含除中文、数字、英文以外的字符!';
} else if (menuName.replace(/[\u4e00-\u9fa5]/g, "**").length > 8) {
} else if (menuName.replace(/[\u4e00-\u9fa5]/g, '**').length > 8) {
return '字符串长度超过限制!';
}
return '';
},
confirmSubName(menuName: string) {
if (Object.prototype.toString.call(menuName).slice(8, -1).toLowerCase() !== 'string') {
if (
Object.prototype.toString
.call(menuName)
.slice(8, -1)
.toLowerCase() !== 'string'
) {
throw Error('param str type error ');
} else if (!menuName) {
return '请输入子菜单名称';
} else if (!/^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(menuName)) {
return '字符串中包含除中文、数字、英文以外的字符!';
} else if (menuName.replace(/[\u4e00-\u9fa5]/g, "**").length > 16) {
} else if (menuName.replace(/[\u4e00-\u9fa5]/g, '**').length > 16) {
return '字符串长度超过限制!';
}
return '';
},
confirmUrl(url: string) {
const pattern = /^(https:\/\/|http:\/\/)/;
if(!pattern.test(url)) {
if (!pattern.test(url)) {
return '公众号链接需要以https://或http://开头';
}
},
@ -80,37 +90,60 @@ export default OakComponent({
deleteMenuContent(index: number, currentIndex?: number) {
const { config, changeConfig } = this.props;
if (typeof currentIndex === 'number') {
config!.button![currentIndex].sub_button[index] = { name: config!.button![currentIndex].sub_button[index].name };
config!.button![currentIndex].sub_button[index] = {
name: config!.button![currentIndex].sub_button[index].name,
};
changeConfig!(config);
} else {
config!.button![index] = { name: config!.button![index].name, sub_button: [...config!.button![index].sub_button] };
config!.button![index] = {
name: config!.button![index].name,
sub_button: [...config!.button![index].sub_button],
};
changeConfig!(config);
}
},
async getMaterialImgAndVoice(type: 'image' | 'voice', media_id: string) {
async getMaterialImgAndVoice(type: 'image' | 'voice', mediaId: string) {
const { applicationId } = this.props;
return new Promise<string | ArrayBuffer | PromiseLike<string | ArrayBuffer | null> | null | undefined>((resolve, reject) => {
this.features.wechatMenu.getMaterial({ applicationId: applicationId!, type, media_id })
.then(file => {
return new Promise<
| string
| ArrayBuffer
| PromiseLike<string | ArrayBuffer | null>
| null
| undefined
>((resolve, reject) => {
this.features.wechatMenu
.getMaterial({
applicationId: applicationId!,
type,
mediaId,
})
.then((file) => {
let reader = new FileReader();
reader.readAsDataURL(file as unknown as Blob);
reader.onload = function (e) {
resolve(e.target?.result);
}
};
})
.catch(error => {
.catch((error) => {
reject(error);
});
});
},
async getMaterialVideo(media_id: string) {
async getMaterialVideo(mediaId: string) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getMaterial({ applicationId: applicationId!, type: 'video', media_id });
const result = await this.features.wechatMenu.getMaterial({
applicationId: applicationId!,
type: 'video',
mediaId,
});
if (result && result.down_url) {
return { url: result.down_url, media_id }
return { url: result.down_url, media_id: mediaId };
}
},
decideMenuContentLabel(decidedMenuContent: any, type: 'news' | 'image' | 'voice' | 'video' | 'text') {
decideMenuContentLabel(
decidedMenuContent: any,
type: 'news' | 'image' | 'voice' | 'video' | 'text'
) {
if (!decidedMenuContent && type !== 'text') {
return '菜单内容';
} else if (decidedMenuContent) {
@ -130,33 +163,47 @@ export default OakComponent({
return '文字'; // 默认值
}
},
async getArticle(article_id: string) {
async getArticle(articleId: string) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getArticle({ applicationId: applicationId!, article_id });
const result = await this.features.wechatMenu.getArticle({
applicationId: applicationId!,
articleId,
});
if (result && result.news_item) {
const modifiedResult = await Promise.all(result.news_item.map(async (ele: any) => {
const coverUrl = await this.getMaterialImgAndVoice('image', ele.thumb_media_id);
return {
...ele,
coverUrl
};
}));
return modifiedResult
const modifiedResult = await Promise.all(
result.news_item.map(async (ele: any) => {
const coverUrl = await this.getMaterialImgAndVoice(
'image',
ele.thumb_media_id
);
return {
...ele,
coverUrl,
};
})
);
return modifiedResult;
}
},
checkError(arr: any[]) {
const { getErrorIndex } = this.props
const { getErrorIndex } = this.props;
const errorIndex = [] as number[];
arr.map((ele, index: number) => {
if (ele.sub_button && ele.sub_button.length > 0) {
ele.sub_button.map((ele: any, index2: number) => {
if (Object.keys(ele).length === 1 && ele.hasOwnProperty('name')) {
if (
Object.keys(ele).length === 1 &&
ele.hasOwnProperty('name')
) {
errorIndex.push((index + 1) * 10 + index2);
}
})
});
} else {
if (Object.keys(ele).length === 2 && ele.hasOwnProperty('name')) {
console.log(index)
if (
Object.keys(ele).length === 2 &&
ele.hasOwnProperty('name')
) {
console.log(index);
errorIndex.push(index);
}
}
@ -164,41 +211,57 @@ export default OakComponent({
this.setState({
errorIndex,
});
getErrorIndex!(errorIndex)
return errorIndex
getErrorIndex!(errorIndex);
return errorIndex;
},
async createMenu(errorInfo: string, errorUrlInfo: string) {
if(errorInfo) {
if (errorInfo) {
this.setMessage({
type: 'warning',
content: '菜单名称有误'
content: '菜单名称有误',
});
return;
}
if(errorUrlInfo) {
if (errorUrlInfo) {
this.setMessage({
type: 'warning',
content: '公众号链接有误'
content: '公众号链接有误',
});
return;
}
const { applicationId, config, changeConfig, changePublishState, createMenu, menuType, changeMenuId } = this.props;
if (this.checkError(config.button).length === 0 && config.button.length > 0) {
const {
applicationId,
config,
changeConfig,
changePublishState,
createMenu,
menuType,
changeMenuId,
} = this.props;
if (
this.checkError(config.button).length === 0 &&
config.button.length > 0
) {
changeConfig!(config);
const removeSubTypeAndContent = (obj: any) => {
const { subType, content, ...newObj } = obj;
return newObj;
}
};
const menuConfig = config.button.map((item: any) => {
if (item.sub_button && item.sub_button.length > 0) {
const sub_button = item.sub_button.map(removeSubTypeAndContent);
const sub_button = item.sub_button.map(
removeSubTypeAndContent
);
return { ...removeSubTypeAndContent(item), sub_button };
} else {
return removeSubTypeAndContent(item);
}
});
if (menuType === 'common') {
const result = await this.features.wechatMenu.createMenu({ applicationId: applicationId!, menuConfig: { button: menuConfig } });
const result = await this.features.wechatMenu.createMenu({
applicationId: applicationId!,
menuConfig: { button: menuConfig },
});
if (result.success) {
changePublishState!('success');
} else {
@ -206,8 +269,15 @@ export default OakComponent({
}
await createMenu!();
} else {
const button = { button: menuConfig, matchrule: config.matchrule }
const result = await this.features.wechatMenu.createConditionalMenu({ applicationId: applicationId!, menuConfig: button });
const button = {
button: menuConfig,
matchrule: config.matchrule,
};
const result =
await this.features.wechatMenu.createConditionalMenu({
applicationId: applicationId!,
menuConfig: button,
});
if (result.success) {
changeMenuId!(result.menuid);
changePublishState!('success');
@ -220,31 +290,34 @@ export default OakComponent({
if (config.button.length === 0) {
this.setMessage({
content: '请添加自定义菜单',
type: 'warning'
type: 'warning',
});
return;
}
if ((this.checkError(config.button).length > 0)) {
if (this.checkError(config.button).length > 0) {
this.setMessage({
content: '请添加菜单消息',
type: 'warning'
type: 'warning',
});
return;
}
}
},
async deleteConditionalMenu() {
const { applicationId, deleteMenu, menuIndex, menuId, createMenu } = this.props;
const result = await this.features.wechatMenu.deleteConditionalMenu({ applicationId: applicationId!, menuid: menuId! });
const { applicationId, deleteMenu, menuIndex, menuId, createMenu } =
this.props;
const result = await this.features.wechatMenu.deleteConditionalMenu(
{ applicationId: applicationId!, menuId: menuId! }
);
if (result.success) {
deleteMenu!();
await createMenu!()
await createMenu!();
} else {
this.setMessage({
type: 'error',
content: result.errmsg
})
content: result.errmsg,
});
}
}
}
},
},
});

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,12 @@
import { WechatMpInstance, WechatPublicInstance, WechatSDK } from 'oak-external-sdk';
import { WechatMpConfig, WechatPublicConfig } from '../../../oak-app-domain/Application/Schema';
import {
WechatMpInstance,
WechatPublicInstance,
WechatSDK,
} from 'oak-external-sdk';
import {
WechatMpConfig,
WechatPublicConfig,
} from '../../../oak-app-domain/Application/Schema';
export default OakComponent({
isList: false,
properties: {
@ -7,14 +14,25 @@ export default OakComponent({
news: [] as any[],
applicationId: '',
},
data: {
},
data: {},
methods: {
async getMaterialImgAndVoice(type: 'image' | 'voice', media_id: string) {
const { applicationId } = this.props
const imgFile = await this.features.wechatMenu.getMaterial({ applicationId: applicationId!, type, media_id });
return new Promise<string | ArrayBuffer | PromiseLike<string | ArrayBuffer | null> | null | undefined>((resolve) => {
async getMaterialImgAndVoice(
type: 'image' | 'voice',
mediaId: string
) {
const { applicationId } = this.props;
const imgFile = await this.features.wechatMenu.getMaterial({
applicationId: applicationId!,
type,
mediaId,
});
return new Promise<
| string
| ArrayBuffer
| PromiseLike<string | ArrayBuffer | null>
| null
| undefined
>((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);
reader.onload = function (e) {
@ -22,26 +40,38 @@ export default OakComponent({
};
});
},
async getArticle(article_id: string) {
async getArticle(articleId: string) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getArticle({ applicationId: applicationId!, article_id });
const result = await this.features.wechatMenu.getArticle({
applicationId: applicationId!,
articleId,
});
if (result && result.news_item) {
const modifiedResult = await Promise.all(result.news_item.map(async (ele: any) => {
const coverUrl = await this.getMaterialImgAndVoice('image', ele.thumb_media_id);
return {
...ele,
coverUrl
};
}));
return modifiedResult
const modifiedResult = await Promise.all(
result.news_item.map(async (ele: any) => {
const coverUrl = await this.getMaterialImgAndVoice(
'image',
ele.thumb_media_id
);
return {
...ele,
coverUrl,
};
})
);
return modifiedResult;
}
},
async getMaterialVideo(media_id: string) {
async getMaterialVideo(mediaId: string) {
const { applicationId } = this.props;
const result = await this.features.wechatMenu.getMaterial({ applicationId: applicationId!, type: 'video', media_id });
const result = await this.features.wechatMenu.getMaterial({
applicationId: applicationId!,
type: 'video',
mediaId,
});
if (result && result.down_url) {
return { url: result.down_url, media_id }
return { url: result.down_url, media_id: mediaId };
}
},
}
});
},
});

View File

@ -21,7 +21,7 @@ export default function Render(
{
getMaterialImgAndVoice: (type: 'image' | 'voice', media_id: string) => Promise<string>;
getArticle: (article_id: string) => Promise<any[]>;
getMaterialVideo: (media_id: string) => { url: string, media_id: string };
getMaterialVideo: (mediaId: string) => { url: string, media_id: string };
}
>
) {

View File

@ -1,4 +1,3 @@
export default OakComponent({
isList: false,
properties: {
@ -8,49 +7,70 @@ export default OakComponent({
},
lifetimes: {
async ready() {
const {applicationId} = this.props
const { applicationId } = this.props;
if (applicationId) {
this.getArticleList(1);
}
}
},
},
methods: {
async getArticleList(page: number) {
const { applicationId } = this.props;
const offset = (page - 1) * 10;
const result = await this.features.wechatMenu.batchGetArticle({ applicationId: applicationId!, offset, count: 10, noContent: 0 });
const modifiedResult = await Promise.all(result.item.map(async (ele: any) => {
const news_item = await Promise.all(ele.content.news_item.map(async (ele2: any) => {
const coverUrl = await this.getMaterialImg(ele2.thumb_media_id);
return {
...ele2,
coverUrl
};
}));
return {
...ele,
content: {
...ele.content,
news_item
}
};
}));
const result = await this.features.wechatMenu.batchGetArticle({
applicationId: applicationId!,
offset,
count: 10,
noContent: 0,
});
const modifiedResult = await Promise.all(
result.item.map(async (ele: any) => {
const news_item = await Promise.all(
ele.content.news_item.map(async (ele2: any) => {
const coverUrl = await this.getMaterialImg(
ele2.thumb_media_id
);
return {
...ele2,
coverUrl,
};
})
);
return {
...ele,
content: {
...ele.content,
news_item,
},
};
})
);
this.setState({
materials: modifiedResult,
total: result.total_count,
});
},
async getMaterialImg(media_id: string) {
async getMaterialImg(mediaId: string) {
const { applicationId } = this.props;
const imgFile = await this.features.wechatMenu.getMaterial({ applicationId: applicationId!, type: 'image', media_id });
return new Promise<string | ArrayBuffer | PromiseLike<string | ArrayBuffer | null> | null | undefined>((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);
reader.onload = function (e) {
resolve(e.target?.result);
};
const imgFile = await this.features.wechatMenu.getMaterial({
applicationId: applicationId!,
type: 'image',
mediaId,
});
}
}
});
return new Promise<
| string
| ArrayBuffer
| PromiseLike<string | ArrayBuffer | null>
| null
| undefined
>((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(imgFile);
reader.onload = function (e) {
resolve(e.target?.result);
};
});
},
},
});

View File

@ -4,11 +4,8 @@ import ConditionalMenu from './conditionalMenu';
import { WebComponentProps } from 'oak-frontend-base';
import { EntityDict } from '../../oak-app-domain';
import Style from './web.module.less';
import { WechatMpInstance, WechatPublicInstance, WechatSDK } from 'oak-external-sdk';
import { WechatMpConfig, WechatPublicConfig } from '../../oak-app-domain/Application/Schema';
import { Row, Col, Tabs } from 'antd';
import type { TabsProps } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import TagList from './tagList';
export default function Render(

View File

@ -60,7 +60,7 @@ export class WechatMenu<
async deleteConditionalMenu(params: {
applicationId: string,
menuid: number
menuId: number
},) {
const callBack = await this.cache.exec('deleteConditionalMenu', params);
return callBack.result;
@ -78,7 +78,7 @@ export class WechatMenu<
async getArticle(params: {
applicationId: string,
article_id: string
articleId: string
},) {
const callBack = await this.cache.exec('getArticle', params);
return callBack.result;
@ -120,7 +120,7 @@ export class WechatMenu<
async getMaterial(params: {
applicationId: string,
type: MenuType,
media_id: string,
mediaId: string,
},) {
const callBack = await this.cache.exec('getMaterial', params);
return callBack.result;