promotion.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { queenApi } from "queenjs";
  2. import { ResourceModule } from "..";
  3. import { getPathname } from "@/dict";
  4. export const promotionAction = ResourceModule.action({
  5. async renamePromotion(record: any) {
  6. const title = await queenApi.showInput({
  7. title: "请输入标题",
  8. defaultValue: record.title,
  9. });
  10. if (!title) return;
  11. await this.https.updatePromotion({ _id: record._id, title });
  12. record.title = title;
  13. },
  14. async publishPromotion(record: any, publish: boolean) {
  15. await this.https.publishPromotion(record._id, publish);
  16. record.published = publish;
  17. queenApi.messageSuccess("操作成功!");
  18. },
  19. async deletePromotion(record: any) {
  20. const res = await queenApi.showConfirm({
  21. content: `删除后无法恢复,确定要删除:${record.title}?`,
  22. type: "danger",
  23. });
  24. if (!res) return;
  25. await this.https.deletePromotion(record._id);
  26. // this.controls.promotionListCtrl.fresh();
  27. },
  28. async deleteCustomComp(record: any) {
  29. const res = await queenApi.showConfirm({
  30. content: `删除后无法恢复,确定要删除当前组合?`,
  31. type: "danger",
  32. });
  33. if (!res) return;
  34. await this.https.deleteComp(record._id);
  35. },
  36. async deleteUserComp(record: any, title: string) {
  37. const res = await queenApi.showConfirm({
  38. content: `删除后无法恢复,确定要删除当前${title}:${record.title}?`,
  39. type: "danger",
  40. });
  41. if (!res) return;
  42. await this.https.deleteComp(record._id);
  43. },
  44. async editSource(record: any, sourceType: string) {
  45. // const itemRes = await this.https.detailComp(record._id);
  46. // if (itemRes.errorNo != 200) {
  47. // queenApi.messageWarn("未查询到数据!");
  48. // return;
  49. // }
  50. let type = sourceType.toLowerCase();
  51. const res = await this.showModal(
  52. <this.components.SouceModal item={record} sourceType={type} />,
  53. {
  54. width: "360px",
  55. title: "编辑",
  56. maskClosable: false,
  57. }
  58. );
  59. if (type == "image" || type == "video") {
  60. await this.https.updateResouce(res);
  61. } else if (type == "template") {
  62. await this.https.updatePromotion(res);
  63. } else {
  64. await this.https.updateComp(res);
  65. }
  66. queenApi.messageSuccess("保存成功");
  67. },
  68. async createPromotion() {
  69. // const title = await queenApi.showInput({
  70. // title: "请输入标题",
  71. // });
  72. const data = await this.showModal(
  73. <this.components.PromotionCreate sourceType="template" />,
  74. {
  75. width: "340px",
  76. maskClosable: false,
  77. title: "新建",
  78. }
  79. );
  80. if (!data) return;
  81. const res = await this.https.createPromotion(data);
  82. //console.log(location.host, location.host == "www.infish.cn");
  83. // if (location.host == "www.infish.cn") {
  84. // const url = `${location.origin}${location.pathname}/projects/queenshowv1/editor.html#/?id=${res.result}`;
  85. // location.href = url;
  86. // return;
  87. // }
  88. const url = `${location.origin}${getPathname()}editor.html#/?id=${res.result}`;
  89. location.href = url;
  90. },
  91. async createComp() {
  92. const title = await queenApi.showInput({
  93. title: "请输入标题",
  94. });
  95. if (!title) return;
  96. const res = await this.https.createComp({ title });
  97. // console.log(location.host, location.host == "www.infish.cn");
  98. // if (location.host == "www.infish.cn") {
  99. // const url = `${location.origin}${location.pathname}/projects/queenshowv1/editor.html#/?id=${res.result}&mode=editComp`;
  100. // location.href = url;
  101. // return;
  102. // }
  103. const url = `${location.origin}${getPathname()}editor.html#/?id=${res.result}&mode=editComp`;
  104. location.href = url;
  105. },
  106. async deleteComp(record: any) {
  107. const res = await queenApi.showConfirm({
  108. content: `删除后无法恢复,确定要删除:${record.title}?`,
  109. type: "danger",
  110. });
  111. if (!res) return;
  112. await this.https.deleteComp(record._id);
  113. // this.controls.promotionListCtrl.fresh();
  114. },
  115. async renameComp(record: any) {
  116. const title = await queenApi.showInput({
  117. title: "请输入标题",
  118. defaultValue: record.title,
  119. });
  120. if (!title) return;
  121. await this.https.updateComp({ _id: record._id, title });
  122. record.title = title;
  123. },
  124. });