const.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. import { Badge, Tag } from 'antd'
  2. import { ReactNode } from 'react'
  3. /** 欢迎语模板适用产品 */
  4. export const welcomeTemplateData = [
  5. {
  6. label: '通用',
  7. value: 0
  8. },
  9. {
  10. label: '洗粉',
  11. value: 1
  12. },
  13. {
  14. label: '大主宰',
  15. value: 2
  16. },
  17. {
  18. label: '大队辅导员',
  19. value: 3
  20. }
  21. ]
  22. /** 欢迎语内容组发送模式 */
  23. export const welcomeContentData = [
  24. {
  25. label: '顺序依次发送',
  26. value: 1
  27. },
  28. {
  29. label: '随机发送',
  30. value: 0
  31. }
  32. ]
  33. /** 业务类型 */
  34. export const businessPlanData = [
  35. { label: '付费小说', value: 'NOVEL' },
  36. { label: '小说IAA', value: 'NOVEL_IAA' },
  37. { label: '付费游戏', value: 'GAME' },
  38. { label: '游戏IAA', value: 'GAME_IAA' },
  39. { label: '短剧IAA', value: 'SKIT_IAA' },
  40. ]
  41. export const WEEK_SERIRES = [{ label: '周一', value: 1 }, { label: '周二', value: 2 }, { label: '周三', value: 3 }, { label: '周四', value: 4 }, { label: '周五', value: 5 }, { label: '周六', value: 6 }, { label: '周天', value: 7 }]
  42. export const WEEK_SERIRES_DX: { [x: string]: string } = {
  43. '1': '周一',
  44. '2': '周二',
  45. '3': '周三',
  46. '4': '周四',
  47. '5': '周五',
  48. '6': '周六',
  49. '7': '周天'
  50. }
  51. export const STATUS_ZJ: { [x: string]: JSX.Element } = {
  52. 'TASK_STATUS_CREATE': <Badge status="default" text={'创建中'} />,
  53. 'TASK_STATUS_WAIT': <Badge status="warning" text={'等待中'} />,
  54. 'TASK_STATUS_RUN': <Badge status="processing" text={'执行中'} />,
  55. 'TASK_STATUS_FINISH': <Badge status="success" text={'执行完成'} />,
  56. 'TASK_STATUS_FAIL': <Badge status="error" text={'执行失败'} />,
  57. 'TASK_STATUS_SUSPEND': <Badge color={'purple'} text={'执行暂停'} />,
  58. 'TASK_STATUS_CANCEL': <Badge color={'magenta'} text={'执行取消'} />
  59. }
  60. export enum StatusEnum {
  61. TASK_STATUS_CREATE = '创建中',
  62. TASK_STATUS_WAIT = '等待中',
  63. TASK_STATUS_RUN = '执行中',
  64. TASK_STATUS_FINISH = '执行完成',
  65. TASK_STATUS_FAIL = '执行失败',
  66. TASK_STATUS_SUSPEND = '执行暂停',
  67. TASK_STATUS_CANCEL = '执行取消'
  68. }
  69. export const TIME_TYPE: { [x: string]: string } = {
  70. TIME_TYPE_SINGLE_TIMELY: '立即发送',
  71. TIME_TYPE_SINGLE_PLACE: '定时发送',
  72. TIME_TYPE_REPEAT_DAY: '每日循环',
  73. TIME_TYPE_REPEAT_WEEK: '每周循环',
  74. TIME_TYPE_REPEAT_MONTH: '每月循环'
  75. }
  76. export const TIME_TYPE_ZJ: { [x: string]: ReactNode } = {
  77. TIME_TYPE_SINGLE_TIMELY: <Tag color="#f50">立即发送</Tag>,
  78. TIME_TYPE_SINGLE_PLACE: <Tag color="#2db7f5">定时发送</Tag>,
  79. TIME_TYPE_REPEAT_DAY: <Tag color="#87d068">每日循环</Tag>,
  80. TIME_TYPE_REPEAT_WEEK: <Tag color="#108ee9">每周循环</Tag>,
  81. TIME_TYPE_REPEAT_MONTH: <Tag color="#cd201f">每月循环</Tag>
  82. }
  83. export const GENDER_TYPE: { [x: string]: string } = {
  84. '2': '女',
  85. '1': '男',
  86. '0': '未知'
  87. }
  88. export const EUTTaskStatus = { 0: <Badge status="default" text="创建中" />, 1: <Badge status="processing" text='执行中' />, 2: <Badge status="success" text="执行完成" />, 3: <Badge status="warning" text="暂停" /> }
  89. /**
  90. * 返回处理过的客户继承数据
  91. * @param schedulingStrategyDTO
  92. * @param taskName
  93. * @returns
  94. */
  95. export const getUserInDataData = (schedulingStrategyDTO: any[], taskName?: string): { taskName: string, strategyData: { [x: string]: any }, inheritData: { [x: string]: any }, strategyIndex: number, inheritIndex: number }[] => {
  96. const userInData = []
  97. schedulingStrategyDTO?.forEach((item, index) => {
  98. // 1、策略 名称 、时间、周期
  99. const { inheritDto, ...strategyData } = JSON.parse(JSON.stringify(item))
  100. inheritDto?.forEach((item1, index1) => {
  101. // 2、转移对象、文本
  102. userInData.push({
  103. taskName: taskName || '--',
  104. strategyData,
  105. inheritData: item1,
  106. strategyIndex: index + 1,
  107. inheritIndex: index1 + 1
  108. })
  109. })
  110. })
  111. return userInData
  112. }
  113. /**
  114. * 返回处理过的群发数据
  115. * @param settings
  116. * @returns
  117. */
  118. export const getGroupData = (settings: TASK_CREATE.SettingsProps): {
  119. groupSendName: string,
  120. strategyData: { [x: string]: any },
  121. sendData: { [x: string]: any },
  122. content: { [x: string]: any },
  123. strategyIndex: number,
  124. sendDataIndex: number,
  125. contentIndex: number,
  126. sendMode: 0 | 1,
  127. strategyDataCount: number,
  128. sendDataRowSpan: number,
  129. }[] => {
  130. const msgData = []
  131. settings?.massSendingContent?.massSendingContentDTO?.forEach((mediaItem, index) => {
  132. // 2、策略信息 发送 发送时间
  133. const strategyData = settings?.massSendingStrategy?.strategySettings?.[index]
  134. // 下面总共多少发送对象
  135. const strategyDataCount = mediaItem?.sendContentDto?.reduce((pre, cur) => {
  136. return pre + cur.contentDTO.length
  137. }, 0)
  138. // console.log('策略信息' + (index + 1), strategyData)
  139. mediaItem?.sendContentDto?.forEach((contentItem, contentindex) => {
  140. // 发送对象
  141. const sendData = strategyData?.sendData?.[contentindex]
  142. const sendDataCount = contentItem.contentDTO.length
  143. // console.log('发送对象' + (contentindex + 1), sendData)
  144. // 4、群发内容
  145. contentItem?.contentDTO.forEach((item, i) => {
  146. // console.log('发送内容' + (i + 1), item)
  147. const { sendData: aa, ...sd } = strategyData
  148. msgData.push({
  149. groupSendName: settings?.massSendingStrategy?.groupSendName,
  150. // 策略信息
  151. strategyData: sd,
  152. // 发送模式
  153. sendMode: contentItem?.sendMode,
  154. // 发送对象
  155. sendData,
  156. // 群发内容
  157. content: item,
  158. strategyIndex: index + 1,
  159. sendDataIndex: contentindex + 1,
  160. contentIndex: i + 1,
  161. strategyDataCount,
  162. sendDataRowSpan: i === 0 ? sendDataCount : 0
  163. })
  164. })
  165. })
  166. })
  167. return msgData
  168. }
  169. /**
  170. * 返回处理过的高级群发数据
  171. * @param settings
  172. * @returns
  173. */
  174. export const getHighGroupData = (settings: TASK_CREATE.SettingsProps): {
  175. groupSendName: string,
  176. strategyData: { [x: string]: any },
  177. sendData: { [x: string]: any },
  178. content: { [x: string]: any },
  179. strategyIndex: number,
  180. sendDataIndex: number,
  181. contentIndex: number,
  182. sendMode: 0 | 1,
  183. strategyDataCount: number,
  184. sendDataRowSpan: number,
  185. strategyItemSendDataCount: number
  186. }[] => {
  187. const msgData = []
  188. settings?.highMassSendingContent?.massSendingContentDTO?.forEach((mediaItem, index) => {
  189. // 2、策略信息 发送 发送时间
  190. const strategyData = settings?.highMassSendingStrategy?.strategySettings?.[index]
  191. // 下面总共多少发送对象
  192. const strategyDataCount = mediaItem?.sendContentDto?.reduce((pre, cur) => {
  193. return pre + cur.contentDTO.length
  194. }, 0)
  195. // console.log('策略信息' + (index + 1), strategyData)
  196. mediaItem?.sendContentDto?.forEach((contentItem, contentindex) => {
  197. // 发送对象
  198. const sendData = strategyData?.sendData?.[contentindex]
  199. const strategyItemSendDataCount = strategyData?.sendData.length
  200. const sendDataCount = contentItem.contentDTO.length
  201. // console.log('发送对象' + (contentindex + 1), sendData)
  202. // 4、群发内容
  203. contentItem?.contentDTO.forEach((item, i) => {
  204. // console.log('发送内容' + (i + 1), item)
  205. const { sendData: aa, ...sd } = strategyData
  206. msgData.push({
  207. groupSendName: settings?.highMassSendingStrategy?.groupSendName,
  208. // 策略信息
  209. strategyData: sd,
  210. // 发送模式
  211. sendMode: contentItem?.sendMode,
  212. // 发送对象
  213. sendData,
  214. // 群发内容
  215. content: item,
  216. strategyIndex: index + 1,
  217. sendDataIndex: contentindex + 1,
  218. contentIndex: i + 1,
  219. strategyDataCount,
  220. strategyItemSendDataCount,
  221. sendDataRowSpan: i === 0 ? sendDataCount : 0
  222. })
  223. })
  224. })
  225. })
  226. return msgData
  227. }
  228. /**
  229. * 重置客户继承数据成可编辑数据
  230. * @param externalUserTransferTasksDTO
  231. * @returns
  232. */
  233. export const restoreUserInheritData = (externalUserTransferTasksDTO: { [x: string]: any }) => {
  234. const { taskName, schedulingStrategyDTO } = externalUserTransferTasksDTO
  235. return {
  236. taskName,
  237. schedulingStrategyDTO: schedulingStrategyDTO.map(schedulingStrategyDTOItem => {
  238. const { transferStrategyContentDTOS, ...strategy } = schedulingStrategyDTOItem
  239. return {
  240. ...strategy,
  241. inheritDto: transferStrategyContentDTOS.map(item => {
  242. const { externalUserFilter, transferSuccessMsg } = item
  243. const inherit: { [x: string]: any } = {
  244. transferSuccessMsg
  245. }
  246. if (externalUserFilter) {
  247. inherit.transferType = 'specify'
  248. const { configName, ...configContent } = externalUserFilter
  249. inherit.transferUserDto = {
  250. configName,
  251. configContent
  252. }
  253. } else {
  254. inherit.transferType = 'all'
  255. }
  256. return inherit
  257. })
  258. }
  259. })
  260. }
  261. }
  262. /**
  263. * 重置群发数据为可编辑数据
  264. * @param groupSendTaskAddDTO
  265. */
  266. export const restoreGroupData = (groupSendTaskAddDTO: { [x: string]: any }, configType?: BUSINES_SPLAN_API.ConfigTypeProps) => {
  267. const type = configType || 'USER_GROUP'
  268. const { groupSendName, strategyList } = groupSendTaskAddDTO
  269. const massSendingContentDTO: { [x: string]: any }[] = []
  270. const strategySettings = strategyList.map(item => {
  271. const { taskDetail, ...strategy } = item
  272. const sendContentDto = []
  273. const sendData = taskDetail.map(item1 => {
  274. const { sendMode, contentDTO, externalUserFilter } = item1
  275. sendContentDto.push({
  276. sendMode,
  277. contentDTO: type === 'USER_GROUP' ? contentDTO : contentDTO.map(item2 => {
  278. const { msgType, ...content } = item2
  279. if (msgType === 'TASK_STATUS_MINIPROGRAM') {
  280. const { miniprogram: { appId, page, title, picUrl } } = content
  281. return [{
  282. miniprogramAppid: appId,
  283. miniprogramPage: page,
  284. miniprogramTitle: title,
  285. miniprogramPicurl: picUrl,
  286. mediaType: 'miniprogram'
  287. }]
  288. } else if (msgType === 'TASK_CONTENT_TEXT') {
  289. const { text } = content
  290. return [{
  291. textContent: text?.content,
  292. mediaType: 'text'
  293. }]
  294. } else if (msgType === 'TASK_CONTENT_LINK') {
  295. const { link: { desc, picUrl, title, url } } = content
  296. return [{
  297. linkDesc: desc,
  298. linkPicurl: picUrl,
  299. linkTitle: title,
  300. linkUrl: url,
  301. mediaType: 'link'
  302. }]
  303. } else if (msgType === 'TASK_CONTENT_IMAGE') {
  304. const { image: { picUrl } } = content
  305. return [{
  306. imageUrl: picUrl,
  307. mediaType: 'image'
  308. }]
  309. } else if (msgType === 'TASK_STATUS_VIDEO') {
  310. const { video: { videoUrl } } = content
  311. return [{
  312. videoUrl: videoUrl,
  313. mediaType: 'video'
  314. }]
  315. } else if (msgType === 'TASK_STATUS_FILE') {
  316. const { file: { fileUrl } } = content
  317. return [{
  318. fileUrl: fileUrl,
  319. mediaType: 'file'
  320. }]
  321. }
  322. return {
  323. msgType,
  324. content
  325. }
  326. })
  327. })
  328. if (externalUserFilter) {
  329. const { configName, ...configContent } = externalUserFilter
  330. return {
  331. externalUserType: 'specify',
  332. externalUserFilter: {
  333. configName,
  334. configContent
  335. }
  336. }
  337. }
  338. return {
  339. externalUserType: 'all'
  340. }
  341. })
  342. massSendingContentDTO.push({
  343. sendContentDto
  344. })
  345. return {
  346. ...strategy,
  347. sendData
  348. }
  349. })
  350. return {
  351. massSendingStrategy: {
  352. groupSendName,
  353. strategySettings
  354. },
  355. massSendingContent: {
  356. massSendingContentDTO
  357. }
  358. }
  359. }
  360. export const momentAttachmentList = (attachmentList: any[]) => {
  361. return attachmentList.map((item: any) => {
  362. switch (item.msgType) {
  363. case 'TASK_CONTENT_IMAGE':
  364. return {
  365. mediaType: 'image',
  366. imageUrl: item.image.picUrl,
  367. mediaFormat: item.image.mediaFormat,
  368. mediaSize: item.image.mediaSize,
  369. mediaPlayTime: item.image.mediaPlayTime,
  370. mediaWidth: item.image.mediaWidth,
  371. mediaHeight: item.image.mediaHeight
  372. }
  373. case 'TASK_STATUS_VIDEO':
  374. return {
  375. mediaType: 'video',
  376. videoUrl: item.video.videoUrl,
  377. mediaFormat: item.image.mediaFormat,
  378. mediaSize: item.image.mediaSize,
  379. mediaPlayTime: item.image.mediaPlayTime,
  380. mediaWidth: item.image.mediaWidth,
  381. mediaHeight: item.image.mediaHeight
  382. }
  383. case 'TASK_STATUS_FILE':
  384. return { mediaType: 'file', fileUrl: item.file.fileUrl }
  385. case "TASK_CONTENT_LINK":
  386. return { mediaType: 'link', linkDesc: item.link.desc, linkPicurl: item.link.picUrl, linkTitle: item.link.title, linkUrl: item.link.url }
  387. case 'TASK_STATUS_MINIPROGRAM':
  388. return {
  389. mediaType: 'miniprogram',
  390. miniprogramAppid: item.miniprogram.appId,
  391. miniprogramPage: item.miniprogram.page,
  392. miniprogramPicurl: item.miniprogram.picUrl,
  393. miniprogramTitle: item.miniprogram.title
  394. }
  395. }
  396. })
  397. }
  398. /**
  399. * 重置朋友圈数据为可编辑数据
  400. * @param momentCreateDTO
  401. * @returns
  402. */
  403. export const restoreMomentData = (momentCreateDTO: { [x: string]: any }) => {
  404. const { momentSendName, strategyList } = momentCreateDTO
  405. const friendsContentDTO: { [x: string]: any }[] = []
  406. const strategySettings = strategyList.map(item => {
  407. const { taskDetail, ...params } = item
  408. friendsContentDTO.push({
  409. ...taskDetail,
  410. contentDTO: taskDetail.contentDTO.map(content => {
  411. return {
  412. text: content.text,
  413. attachmentList: momentAttachmentList(content.attachmentList)
  414. }
  415. })
  416. })
  417. return params
  418. })
  419. return {
  420. friendsStrategy: {
  421. momentSendName,
  422. strategySettings
  423. },
  424. friendsContent: {
  425. friendsContentDTO
  426. }
  427. }
  428. }
  429. // excel 配置
  430. // // 复杂表头示例(两级表头)
  431. // import XLSX from "xlsx-js-style";
  432. // const headers = [
  433. // [
  434. // { v: "账号", s: headerStyle },
  435. // { v: '欢迎语标题', s: headerStyle },
  436. // { v: '智能标签', s: headerStyle },
  437. // { v: '内容组发送模式', s: headerStyle },
  438. // { v: '欢迎语内容', s: headerStyle },
  439. // { v: '图文链接', s: headerStyle },
  440. // { v: '小程序APPID', s: headerMustStyle },
  441. // { v: '小程序路径', s: headerMustStyle }
  442. // ]
  443. // ];
  444. // // 数据内容
  445. // const data = settings?.corpUserList?.map((item) => {
  446. // return mediaContent?.map((mediaItem) => {
  447. // return {
  448. // '账号': `${item.name}(${item.corpUserId})`,
  449. // '欢迎语标题': `${welcomeName}`,
  450. // '智能标签': `${business ? `业务:${businessPlanData.find(i => i.value === business)?.label}` : '--'}\n${bookCity ? `书城;${bookPlatForm.find(i => i.id === bookCity)?.platformName}` : '--'}\n${product ? `产品:${bookList.find(i => i.id === product)?.bookName}` : '--'}`,
  451. // '内容组发送模式': welcomeContentData.find(i => i.value === welcomeContentType)?.label,
  452. // '欢迎语内容': '--',
  453. // '图文链接': '--',
  454. // '小程序APPID': '--',
  455. // '小程序路径': '--'
  456. // }
  457. // })
  458. // })
  459. // // 将数据转换为二维数组
  460. // const dataArray = [
  461. // ...headers,
  462. // ...data.map(row => [
  463. // row['账号'],
  464. // row['欢迎语标题'],
  465. // row['智能标签'],
  466. // row['内容组发送模式'],
  467. // row['欢迎语内容'],
  468. // row['图文链接'],
  469. // row['小程序APPID'],
  470. // row['小程序路径']
  471. // ])
  472. // ];
  473. // // 创建工作表并合并单元格
  474. // const worksheet = XLSX.utils.aoa_to_sheet(dataArray);
  475. // worksheet["!rows"] = [{ hpx: 30 }, ...Array(1000).fill({ hpx: 20 })]; // 设置行高
  476. // worksheet['!cols'] = [{ width: 40 }, { width: 25 }, { width: 30 }, { width: 30 }, { width: 40 }, { width: 30 }, { width: 30 }, { width: 30 }]; // 设置列宽
  477. // // worksheet['!merges'] = [
  478. // // // 合并主标题1(合并前两列)
  479. // // { s: { r: 1, c: 0 }, e: { r: 1, c: 1 } }
  480. // // ];
  481. // // 创建工作簿并导出
  482. // const workbook = XLSX.utils.book_new();
  483. // XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
  484. // const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
  485. // const blob = new Blob([excelBuffer], { type: 'application/octet-stream' });
  486. // saveAs(blob, 'complex_data.xlsx');
  487. // console.log(dataArray);
  488. // 表头样式
  489. export const headerStyle = {
  490. font: { bold: true, sz: 14, color: { rgb: "FFFFFF" }, name: "微软雅黑" },
  491. fill: { fgColor: { rgb: "1890FF" } },
  492. alignment: { vertical: "center", horizontal: "center" },
  493. border: {
  494. top: { style: "thin", color: { rgb: "FFFFFF" } },
  495. bottom: { style: "thin", color: { rgb: "FFFFFF" } },
  496. left: { style: "thin", color: { rgb: "FFFFFF" } },
  497. right: { style: "thin", color: { rgb: "FFFFFF" } }
  498. }
  499. };
  500. // 必填样式
  501. export const headerMustStyle = {
  502. font: { bold: true, sz: 14, color: { rgb: "FFFFFF" }, name: "微软雅黑" },
  503. fill: { fgColor: { rgb: "ff7875" } },
  504. alignment: { vertical: "center", horizontal: "center" },
  505. border: {
  506. top: { style: "thin", color: { rgb: "FFFFFF" } },
  507. bottom: { style: "thin", color: { rgb: "FFFFFF" } },
  508. left: { style: "thin", color: { rgb: "FFFFFF" } },
  509. right: { style: "thin", color: { rgb: "FFFFFF" } }
  510. }
  511. };
  512. // JS表格头样式
  513. export const headerJsStyle = {
  514. fill: {
  515. type: 'pattern',
  516. pattern: 'solid',
  517. fgColor: { argb: '1890ff' } // 蓝色背景
  518. },
  519. font: {
  520. name: '微软雅黑',
  521. size: 14,
  522. bold: true,
  523. color: { argb: 'FFFFFF' }
  524. },
  525. alignment: {
  526. vertical: 'middle',
  527. horizontal: 'center'
  528. },
  529. border: {
  530. top: { style: 'thin', color: { argb: 'FFFFFF' } },
  531. bottom: { style: 'thin', color: { argb: 'FFFFFF' } },
  532. left: { style: 'thin', color: { argb: 'FFFFFF' } },
  533. right: { style: 'thin', color: { argb: 'FFFFFF' } }
  534. }
  535. };
  536. // JS必填样式
  537. export const headerJsMustStyle = {
  538. fill: {
  539. type: 'pattern',
  540. pattern: 'solid',
  541. fgColor: { argb: 'ff7875' } // 蓝色背景
  542. },
  543. font: {
  544. name: '微软雅黑',
  545. size: 14,
  546. bold: true,
  547. color: { argb: 'FFFFFF' }
  548. },
  549. alignment: {
  550. vertical: 'middle',
  551. horizontal: 'center'
  552. },
  553. border: {
  554. top: { style: 'thin', color: { argb: 'FFFFFF' } },
  555. bottom: { style: 'thin', color: { argb: 'FFFFFF' } },
  556. left: { style: 'thin', color: { argb: 'FFFFFF' } },
  557. right: { style: 'thin', color: { argb: 'FFFFFF' } }
  558. }
  559. };