index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="mx-3 mt-3" style="display: flex; gap: 14px;">
  3. <el-input v-model="templateList" :prefix-icon="Search" placeholder="快速查询" style="width: 240px" @change=""></el-input>
  4. <el-select v-model="templateType" placeholder="Select" style="width: 240px">
  5. <el-option
  6. v-for="item in TemplateType"
  7. :key="item.value"
  8. :label="item.label"
  9. :value="item.value"
  10. />
  11. </el-select>
  12. </div>
  13. <el-card class="mx-3 my-3">
  14. <vxe-grid v-bind="gridOptions" v-on="gridEvents">
  15. <template #toolbar_buttons>
  16. <SelectBotton :options="TemplateType" btn-title="新建模板" @click="createTmpl"></SelectBotton>
  17. </template>
  18. <template #operate="{ row }">
  19. <el-button icon="Edit" type="text" @click="editTmpl(row)"></el-button>
  20. <el-button icon="SetUp" type="text" @click="showDialog" :disabled="true"></el-button>
  21. <el-button icon="Delete" type="text" @click=""></el-button>
  22. </template>
  23. </vxe-grid>
  24. </el-card>
  25. <el-drawer v-model="showDrawer" :close-on-click-modal="false" :destroy-on-close="true"
  26. :title="mode === 'add' ? '新建模板' : '编辑模板'"
  27. size="70%">
  28. <div style="padding: 0 15px">
  29. <component
  30. :is="dyComponents[formData.rule.type]"
  31. :data="formData"
  32. :mode="mode"
  33. :submitFormData="submitFormData"
  34. @refresh="refreshTable"></component>
  35. </div>
  36. </el-drawer>
  37. <AdActivityDialog v-model:visible="isDialogVisible" />
  38. </template>
  39. <script lang="ts" setup>
  40. import { onMounted, provide, reactive, ref, Ref } from 'vue';
  41. import { Search } from '@element-plus/icons-vue';
  42. import { TemplateType } from '../utils/enum';
  43. import { GetList } from '/@/views/efTools/automation/api';
  44. import SelectBotton from '/@/components/select-button/index.vue';
  45. import TimerBidTmpl from '/@/views/components/auto/auto-templates/timer-bid.vue';
  46. import TimerBudgetTmpl from '/@/views/components/auto/auto-templates/timer-budget.vue';
  47. import SwitchCampaignTmpl from '/@/views/components/auto/auto-templates/switch-campaign.vue';
  48. import TargetRuleTmpl from '/@/views/components/auto/auto-templates/target-rule.vue';
  49. import SearchTermTmpl from '/@/views/components/auto/auto-templates/search-term.vue';
  50. import NegKeywordTmpl from '/@/views/components/auto/auto-templates/neg-keyword.vue';
  51. import AdActivityDialog from './components/adActivityDialog.vue';
  52. import { AddObj, UpdateObj } from './api';
  53. const isDialogVisible = ref(false);
  54. const showDialog = () => {
  55. isDialogVisible.value = true;
  56. };
  57. provide('isDialogVisible',isDialogVisible)
  58. //查询
  59. const templateList = ref('');
  60. const templateType = ref('');
  61. //创建,编辑
  62. const mode = ref('');
  63. const showDrawer = ref(false);
  64. const formData: Ref<AutoTemplate> = ref({
  65. name: '',
  66. rule: {
  67. type: 0,
  68. campaignType: '',
  69. campaignAd: [],
  70. action: {},
  71. activeModel: '',
  72. setTime: '',
  73. weekdays: [],
  74. conditions: [],
  75. },
  76. });
  77. const dyComponents = {
  78. 1: TimerBidTmpl,
  79. 2: TimerBudgetTmpl,
  80. 3: SwitchCampaignTmpl,
  81. 4: TargetRuleTmpl,
  82. 5: SearchTermTmpl,
  83. 6: NegKeywordTmpl,
  84. };
  85. const refreshTable = () => {
  86. showDrawer.value = false;
  87. getList();
  88. };
  89. const createTmpl = (val: number) => {
  90. mode.value = 'add';
  91. delete formData.value.id;
  92. formData.value.name = '';
  93. formData.value.rule = {
  94. type: val,
  95. campaignType: '',
  96. campaignAd: [],
  97. action: {},
  98. activeModel: '',
  99. setTime: '',
  100. weekdays: [],
  101. conditions: [],
  102. };
  103. //console.log(formData.value);
  104. showDrawer.value = true;
  105. };
  106. const editTmpl = (row: any) => {
  107. mode.value = 'edit';
  108. formData.value.id = row.id;
  109. formData.value.name = row.name;
  110. formData.value.rule = row.rule;
  111. showDrawer.value = true;
  112. };
  113. const submitFormData = async () => {
  114. if (mode.value === 'add') {
  115. await AddObj(formData.value);
  116. } else if (mode.value === 'edit') {
  117. await UpdateObj(formData.value);
  118. }
  119. refreshTable();
  120. };
  121. //表格配置
  122. const gridOptions = reactive({
  123. border: 'inner',
  124. height: 900,
  125. align: null,
  126. loading: false,
  127. rowConfig: {
  128. isHover: true,
  129. },
  130. columnConfig: {
  131. resizable: true,
  132. },
  133. pagerConfig: {
  134. enabled: true,
  135. total: 20,
  136. currentPage: 1,
  137. pageSize: 20,
  138. pageSizes: [10, 20, 30],
  139. },
  140. columns: [
  141. {field: 'id', title: 'ID'},
  142. {field: 'name', title: '模板名称'},
  143. {field: 'rule.type', title: '模板类型', formatter: ({cellValue}) => getTemplateTypeLabel(cellValue)},
  144. {field: 'campaignNumber', title: '广告活动数量'},
  145. {field: 'creator_username', title: '创建人'},
  146. {field: 'modifier_username', title: '修改人'},
  147. {title: '操作', width: 120, slots: {default: 'operate'}},
  148. ],
  149. toolbarConfig: {
  150. slots: {
  151. buttons: 'toolbar_buttons',
  152. },
  153. },
  154. data: [],
  155. });
  156. const gridEvents = {
  157. pageChange({currentPage, pageSize}) {
  158. if (gridOptions.pagerConfig) {
  159. gridOptions.pagerConfig.currentPage = currentPage;
  160. gridOptions.pagerConfig.pageSize = pageSize;
  161. getList();
  162. }
  163. },
  164. };
  165. async function getList() {
  166. try {
  167. gridOptions.loading = true;
  168. const response = await GetList({
  169. page: gridOptions.pagerConfig.currentPage,
  170. limit: gridOptions.pagerConfig.pageSize,
  171. });
  172. gridOptions.data = response.data.map(item => ({
  173. ...item,
  174. rule: {
  175. ...item.rule,
  176. typeLabel: getTemplateTypeLabel(item.rule.type),
  177. },
  178. }));
  179. console.log(response.data);
  180. gridOptions.pagerConfig.total = response.total;
  181. } catch (error) {
  182. console.error('Error fetching task data:', error);
  183. } finally {
  184. gridOptions.loading = false;
  185. }
  186. }
  187. function getTemplateTypeLabel(type: number) {
  188. const template = TemplateType.find(t => t.value === type);
  189. return template ? template.label : '';
  190. }
  191. onMounted(() => {
  192. getList();
  193. });
  194. </script>
  195. <style>
  196. .custom-inline {
  197. display: flex;
  198. justify-content: space-around;
  199. margin: 12px 0;
  200. gap: 4px;
  201. }
  202. .custom-dialog .el-dialog__header {
  203. height: 60px;
  204. line-height: 60px;
  205. padding: 0 24px;
  206. background-color: #fff;
  207. border-bottom: 1px solid #e5e6eb;
  208. border-radius: 10px 10px 0 0;
  209. }
  210. </style>