const.tsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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. // excel 配置
  361. // // 复杂表头示例(两级表头)
  362. // import XLSX from "xlsx-js-style";
  363. // const headers = [
  364. // [
  365. // { v: "账号", s: headerStyle },
  366. // { v: '欢迎语标题', s: headerStyle },
  367. // { v: '智能标签', s: headerStyle },
  368. // { v: '内容组发送模式', s: headerStyle },
  369. // { v: '欢迎语内容', s: headerStyle },
  370. // { v: '图文链接', s: headerStyle },
  371. // { v: '小程序APPID', s: headerMustStyle },
  372. // { v: '小程序路径', s: headerMustStyle }
  373. // ]
  374. // ];
  375. // // 数据内容
  376. // const data = settings?.corpUserList?.map((item) => {
  377. // return mediaContent?.map((mediaItem) => {
  378. // return {
  379. // '账号': `${item.name}(${item.corpUserId})`,
  380. // '欢迎语标题': `${welcomeName}`,
  381. // '智能标签': `${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}` : '--'}`,
  382. // '内容组发送模式': welcomeContentData.find(i => i.value === welcomeContentType)?.label,
  383. // '欢迎语内容': '--',
  384. // '图文链接': '--',
  385. // '小程序APPID': '--',
  386. // '小程序路径': '--'
  387. // }
  388. // })
  389. // })
  390. // // 将数据转换为二维数组
  391. // const dataArray = [
  392. // ...headers,
  393. // ...data.map(row => [
  394. // row['账号'],
  395. // row['欢迎语标题'],
  396. // row['智能标签'],
  397. // row['内容组发送模式'],
  398. // row['欢迎语内容'],
  399. // row['图文链接'],
  400. // row['小程序APPID'],
  401. // row['小程序路径']
  402. // ])
  403. // ];
  404. // // 创建工作表并合并单元格
  405. // const worksheet = XLSX.utils.aoa_to_sheet(dataArray);
  406. // worksheet["!rows"] = [{ hpx: 30 }, ...Array(1000).fill({ hpx: 20 })]; // 设置行高
  407. // worksheet['!cols'] = [{ width: 40 }, { width: 25 }, { width: 30 }, { width: 30 }, { width: 40 }, { width: 30 }, { width: 30 }, { width: 30 }]; // 设置列宽
  408. // // worksheet['!merges'] = [
  409. // // // 合并主标题1(合并前两列)
  410. // // { s: { r: 1, c: 0 }, e: { r: 1, c: 1 } }
  411. // // ];
  412. // // 创建工作簿并导出
  413. // const workbook = XLSX.utils.book_new();
  414. // XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
  415. // const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
  416. // const blob = new Blob([excelBuffer], { type: 'application/octet-stream' });
  417. // saveAs(blob, 'complex_data.xlsx');
  418. // console.log(dataArray);
  419. // 表头样式
  420. export const headerStyle = {
  421. font: { bold: true, sz: 14, color: { rgb: "FFFFFF" }, name: "微软雅黑" },
  422. fill: { fgColor: { rgb: "1890FF" } },
  423. alignment: { vertical: "center", horizontal: "center" },
  424. border: {
  425. top: { style: "thin", color: { rgb: "FFFFFF" } },
  426. bottom: { style: "thin", color: { rgb: "FFFFFF" } },
  427. left: { style: "thin", color: { rgb: "FFFFFF" } },
  428. right: { style: "thin", color: { rgb: "FFFFFF" } }
  429. }
  430. };
  431. // 必填样式
  432. export const headerMustStyle = {
  433. font: { bold: true, sz: 14, color: { rgb: "FFFFFF" }, name: "微软雅黑" },
  434. fill: { fgColor: { rgb: "ff7875" } },
  435. alignment: { vertical: "center", horizontal: "center" },
  436. border: {
  437. top: { style: "thin", color: { rgb: "FFFFFF" } },
  438. bottom: { style: "thin", color: { rgb: "FFFFFF" } },
  439. left: { style: "thin", color: { rgb: "FFFFFF" } },
  440. right: { style: "thin", color: { rgb: "FFFFFF" } }
  441. }
  442. };
  443. // JS表格头样式
  444. export const headerJsStyle = {
  445. fill: {
  446. type: 'pattern',
  447. pattern: 'solid',
  448. fgColor: { argb: '1890ff' } // 蓝色背景
  449. },
  450. font: {
  451. name: '微软雅黑',
  452. size: 14,
  453. bold: true,
  454. color: { argb: 'FFFFFF' }
  455. },
  456. alignment: {
  457. vertical: 'middle',
  458. horizontal: 'center'
  459. },
  460. border: {
  461. top: { style: 'thin', color: { argb: 'FFFFFF' } },
  462. bottom: { style: 'thin', color: { argb: 'FFFFFF' } },
  463. left: { style: 'thin', color: { argb: 'FFFFFF' } },
  464. right: { style: 'thin', color: { argb: 'FFFFFF' } }
  465. }
  466. };
  467. // JS必填样式
  468. export const headerJsMustStyle = {
  469. fill: {
  470. type: 'pattern',
  471. pattern: 'solid',
  472. fgColor: { argb: 'ff7875' } // 蓝色背景
  473. },
  474. font: {
  475. name: '微软雅黑',
  476. size: 14,
  477. bold: true,
  478. color: { argb: 'FFFFFF' }
  479. },
  480. alignment: {
  481. vertical: 'middle',
  482. horizontal: 'center'
  483. },
  484. border: {
  485. top: { style: 'thin', color: { argb: 'FFFFFF' } },
  486. bottom: { style: 'thin', color: { argb: 'FFFFFF' } },
  487. left: { style: 'thin', color: { argb: 'FFFFFF' } },
  488. right: { style: 'thin', color: { argb: 'FFFFFF' } }
  489. }
  490. };