index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div class="layout-padding">
  3. <div class="layout-padding-auto layout-padding-view">
  4. <el-row shadow="hover" v-show="showSearch" class="ml10">
  5. <el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList" ref="queryRef">
  6. <el-form-item :label="t('marketingApps.name')" prop="domain">
  7. <el-input :placeholder="t('marketingApps.inputNameTip')" clearable
  8. v-model="state.queryForm.domain" />
  9. </el-form-item>
  10. <el-form-item :label="'应用ID'" prop="appId">
  11. <el-input :placeholder="'请输入应用ID'" clearable v-model="state.queryForm.appId" />
  12. </el-form-item>
  13. <el-form-item :label="'应用类型'" prop="domainSelected">
  14. <el-select placeholder="请选择应用类型" v-model="state.queryForm.domainSelected">
  15. <el-option v-for="item in domainTypeOptions" :key="item.value" :label="item.description" :value="item.value" />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item :label="'备注'" prop="remark">
  19. <el-input :placeholder="'请输入备注'" clearable v-model="state.queryForm.remark" />
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button @click="query" class="ml10" icon="search" type="primary">
  23. {{ t('common.queryBtn') }}
  24. </el-button>
  25. <el-button @click="resetQuery" icon="Refresh">{{ t('common.resetBtn') }}</el-button>
  26. <el-button @click="handleEdit" icon="EditPen" :disabled="activeName === 'tab2'">{{ t('common.editBtn') }}</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </el-row>
  30. <!-- <el-row>
  31. <div class="mb8" style="width: 100%">
  32. <right-toolbar v-model:showSearch="showSearch" class="ml10" style="float: right; margin-right: 20px"
  33. @queryTable="getDataList"></right-toolbar>
  34. </div>
  35. </el-row> -->
  36. <el-tabs v-model="activeName" class="table-tabs" @tab-click="handleClick">
  37. <el-tab-pane label="使用中" name="tab1"></el-tab-pane>
  38. <el-tab-pane label="回收站" name="tab2"></el-tab-pane>
  39. </el-tabs>
  40. <el-table @selection-change="handleSelectionChange" ref="tableRef" :data="state.dataList" row-key="path"
  41. style="width: 100%" v-loading="state.loading" border :cell-style="tableStyle.cellStyle"
  42. :header-cell-style="tableStyle?.headerCellStyle">
  43. <el-table-column type="selection" fixed="left" width="55" v-if="activeName == 'tab1'" />
  44. <el-table-column fixed="left" :label="t('marketingApps.id')" prop="id" width="80" show-overflow-tooltip>
  45. <template #default="{ row }">{{ row.id }}</template>
  46. </el-table-column>
  47. <el-table-column :label="t('marketingApps.appId')" prop="appId" width="120" show-overflow-tooltip>
  48. <template #default="{ row }">{{ row.appId }}</template>
  49. </el-table-column>
  50. <el-table-column :label="t('marketingApps.appImg')" prop="appImg" width="150" show-overflow-tooltip>
  51. <template #default="{ row }" style="display: flex; align-self: center;">
  52. <el-image style="width: 80px; height: 80px; border-radius: 10px;" :src="row.appImg" :fit="fit" />
  53. </template>
  54. </el-table-column>
  55. <el-table-column :label="t('marketingApps.name')" prop="appName" width="150" show-overflow-tooltip>
  56. <template #default="{ row }">
  57. <el-link :href="row.url">{{ row.appName }}</el-link>
  58. </template>
  59. </el-table-column>
  60. <el-table-column :label="t('marketingApps.appType')" prop="domainType" width="110" show-overflow-tooltip>
  61. <template #default="{ row }">
  62. <el-select @change="handleChange(row)" :disabled="activeName === 'tab2'" v-model="row.domainType" placeholder="" style="width: 80px">
  63. <el-option v-for="item in domainTypeOptions" :key="item.value" :label="item.description" :value="item.value" />
  64. </el-select>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="营销投放" prop="launch" width="120">
  68. <template #default="{ row }">
  69. <el-switch :disabled="activeName === 'tab2'" v-model="row.launch" inline-prompt :active-value="true"
  70. :inactive-value="false" @change="handleChange(row)" />
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="域名限制" prop="domainLimit" width="120">
  74. <template #default="{ row }">
  75. <el-switch :disabled="activeName === 'tab2'" v-model="row.domainLimit" inline-prompt :active-value="true"
  76. :inactive-value="false" @change="handleChange(row)" />
  77. </template>
  78. </el-table-column>
  79. <el-table-column :label="'域名集合'" prop="domains" width="280" show-overflow-tooltip>
  80. <template #default="{ row }">
  81. <DomainCell :domainList="row.domains" :rowData="row" @refresh="getDataList()" />
  82. </template>
  83. </el-table-column>
  84. <el-table-column :label="'IP集合'" prop="ips" width="320">
  85. <template #default="{ row }">
  86. <IpCell :ipList="row.ips" :rowData="row" @refresh="getDataList()" />
  87. </template>
  88. </el-table-column>
  89. <el-table-column :label="'触发频率'" prop="triggerNum" width="150" show-overflow-tooltip>
  90. <template #default="{ row }">
  91. <!-- <el-input-number v-model="row.triggerNum" :max=20 /> -->
  92. {{ row.triggerNum }}
  93. </template>
  94. </el-table-column>
  95. <el-table-column :label="t('marketingApps.triggerRule')" width="140" prop="triggerRule" show-overflow-tooltip>
  96. <template #default="{ row }">
  97. <el-select @change="handleChange(row)" :disabled="activeName === 'tab2'" v-model="row.triggerRule" placeholder="" style="width: 100px">
  98. <el-option v-for="item in triggerRules" :key="item.value" :label="item.label" :value="item.value" />
  99. </el-select>
  100. </template>
  101. </el-table-column>
  102. <el-table-column :label="'备注'" prop="remark" width="150" show-overflow-tooltip>
  103. <template #default="{ row }">
  104. {{ row.remark }}
  105. </template>
  106. </el-table-column>
  107. <el-table-column fixed="right" :label="t('common.action')" width="200">
  108. <template #default="scope">
  109. <div class="action" style="text-align: left;">
  110. <el-button :disabled="activeName == 'tab2'" style="margin-right: 0px;" @click="onOpenEditMenu('edit', scope.row)" text type="primary"
  111. v-auth="'sys_menu_edit'">
  112. <svg style="margin-right: 5px;" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
  113. <mask id="mask0_362_1714" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="16" height="16">
  114. <rect width="16" height="16" fill="#D9D9D9"/>
  115. </mask>
  116. <g mask="url(#mask0_362_1714)">
  117. <path d="M4.60017 12.2954L5.97782 12.2954C6.50827 12.2955 7.017 12.0847 7.39208 11.7097L13.7925 5.30925C14.4017 4.70003 14.4017 3.71229 13.7925 3.10308V3.10308C13.1833 2.49386 12.1955 2.49387 11.5863 3.10308L5.18591 9.5035C4.81082 9.87859 4.60011 10.3873 4.60012 10.9178L4.60017 12.2954Z" stroke="#167AF0" stroke-linejoin="round"/>
  118. <path d="M10.4832 4.20593L12.6893 6.41211" stroke="#167AF0" stroke-linecap="round" stroke-linejoin="round"/>
  119. <path d="M8.5 2H4C2.89543 2 2 2.89543 2 4V13C2 14.1046 2.89543 15 4 15H13C14.1046 15 15 14.1046 15 13V8.5" stroke="#167AF0" stroke-linecap="round"/>
  120. </g>
  121. </svg>
  122. 修改</el-button>
  123. <el-button style="margin-right: 0px;" @click="onOpenStatistical(scope.row)" text type="primary"
  124. v-auth="'sys_menu_edit'">
  125. <svg style="margin-right: 5px;" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
  126. <path d="M2 6V3C2 2.44772 2.44772 2 3 2H13C13.5523 2 14 2.44772 14 3V6" stroke="#167AF0" stroke-linecap="round" stroke-linejoin="round"/>
  127. <path d="M10.6667 8V10.3333" stroke="#167AF0" stroke-linecap="round" stroke-linejoin="round"/>
  128. <path d="M8 5V10.3333" stroke="#167AF0" stroke-linecap="round" stroke-linejoin="round"/>
  129. <path d="M5.33325 6.33334V10.3333" stroke="#167AF0" stroke-linecap="round" stroke-linejoin="round"/>
  130. <path d="M2 10V13C2 13.5523 2.44772 14 3 14H13C13.5523 14 14 13.5523 14 13V10" stroke="#167AF0" stroke-linecap="round" stroke-linejoin="round"/>
  131. </svg>
  132. 统计</el-button>
  133. <el-button v-if="activeName == 'tab1'" style="margin-right: 0px;" @click="handleDelete(scope.row)" text type="danger"
  134. v-auth="'sys_menu_edit'">
  135. <svg style="margin-right: 5px;" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
  136. <g clip-path="url(#clip0_35_722)">
  137. <path d="M3 3.33334V12.6667C3 13.7712 3.89543 14.6667 5 14.6667H11C12.1046 14.6667 13 13.7712 13 12.6667V3.33334H3Z" stroke="#E64242" stroke-linejoin="round"/>
  138. <path d="M6.66675 6.66666V11" stroke="#E64242" stroke-linecap="round" stroke-linejoin="round"/>
  139. <path d="M9.33325 6.66666V11" stroke="#E64242" stroke-linecap="round" stroke-linejoin="round"/>
  140. <path d="M1.33325 3.33334H14.6666" stroke="#E64242" stroke-linecap="round" stroke-linejoin="round"/>
  141. <path d="M5.33325 3.33334L6.42959 1.33334H9.59229L10.6666 3.33334H5.33325Z" stroke="#E64242" stroke-linejoin="round"/>
  142. </g>
  143. <defs>
  144. <clipPath id="clip0_35_722">
  145. <rect width="16" height="16" fill="white"/>
  146. </clipPath>
  147. </defs>
  148. </svg>
  149. 拉黑</el-button>
  150. <el-button v-if="activeName == 'tab2'" style="margin-right: 0px;" icon="refresh" @click="handleDelete(scope.row)" text type="success"
  151. v-auth="'sys_menu_edit'">还原</el-button>
  152. </div>
  153. </template>
  154. </el-table-column>
  155. </el-table>
  156. <pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
  157. </div>
  158. <EditDialog @refresh="getDataList()" ref="EditDialogRef" />
  159. <StatisticalDialog @refresh="getDataList()" ref="statisticalDialogRef" />
  160. </div>
  161. </template>
  162. <script lang="ts" name="marketingApps" setup>
  163. import { pageList, pageDel, delAppById, setAppInfo } from '/@/api/marketing/apps';
  164. import { BasicTableProps, useTable } from '/@/hooks/table';
  165. import { useMessage, useMessageBox } from '/@/hooks/message';
  166. import { useI18n } from 'vue-i18n';
  167. import { fetchItemList } from '/@/api/admin/dict';
  168. import { ref } from 'vue'
  169. const EditDialog = defineAsyncComponent(() => import('./components/form.vue'));
  170. const StatisticalDialog = defineAsyncComponent(() => import('./components/statistical.vue'));
  171. const IpCell = defineAsyncComponent(() => import('./components/ipCell.vue'));
  172. const DomainCell = defineAsyncComponent(() => import('./components/domainCell.vue'));
  173. import { ElMessage, type TabsPaneContext } from 'element-plus'
  174. const activeName = ref('tab1')
  175. const handleClick = (tab: TabsPaneContext, event: Event) => {
  176. activeName.value = tab.paneName as string;
  177. query();
  178. }
  179. const { t } = useI18n();
  180. // 定义变量内容
  181. const tableRef = ref();
  182. const EditDialogRef = ref();
  183. const statisticalDialogRef = ref();
  184. const queryRef = ref();
  185. const showSearch = ref(true);
  186. // 多选rows
  187. const selectObjs = ref([]) as any;
  188. // 是否可以多选
  189. const multiple = ref(true);
  190. const state: BasicTableProps = reactive<BasicTableProps>({
  191. pageList: pageList,
  192. createdIsNeed: false,
  193. queryForm: {
  194. appId: '',
  195. appName: '',
  196. domainSelected: '0',
  197. domainType: '',
  198. remark: '',
  199. }
  200. });
  201. const domainTypeOptions = ref([]) as any;
  202. const getDomianTypeList = async () => {
  203. const { data } = await fetchItemList({
  204. dictType: 'DomianType'
  205. });
  206. domainTypeOptions.value = data?.records || [];
  207. domainTypeOptions.value.map((item)=>{
  208. item.value = Number(item.value);
  209. })
  210. domainTypeOptions.value.unshift({
  211. description: '全部',
  212. value: '0'
  213. })
  214. }
  215. getDomianTypeList();
  216. const triggerRules = [
  217. {
  218. label: '仅一次',
  219. value: 1,
  220. },
  221. {
  222. label: '多次',
  223. value: 2,
  224. },
  225. ]
  226. const { getDataList, currentChangeHandle, sizeChangeHandle, tableStyle } = useTable(state);
  227. // 搜索事件
  228. const query = () => {
  229. activeName.value == 'tab1' ? state.pageList = pageList : state.pageList = pageDel;
  230. state.dataList = [];
  231. state.queryForm.domainType = state.queryForm.domainSelected == 0 ? '' : state.queryForm.domainSelected;
  232. getDataList();
  233. };
  234. // 修改单条配置信息
  235. const handleChange = (row: any) => {
  236. setAppInfo(row).then(() => {
  237. useMessage().success('修改成功');
  238. getDataList();
  239. }).catch((err: any) => {
  240. useMessage().error(err.msg);
  241. });
  242. };
  243. // 清空搜索条件
  244. const resetQuery = () => {
  245. queryRef.value.resetFields();
  246. state.dataList = [];
  247. getDataList();
  248. };
  249. // 批量修改配置
  250. const handleEdit = () => {
  251. console.log('selectObjs', selectObjs);
  252. if (selectObjs.value.length === 0) {
  253. useMessage().warning('请选择要修改的项');
  254. return;
  255. }
  256. EditDialogRef.value.openDialog('', selectObjs.value);
  257. };
  258. // 多选
  259. const handleSelectionChange = (selection: any) => {
  260. selectObjs.value = selection;
  261. };
  262. // 打开编辑菜单弹窗
  263. const onOpenEditMenu = (type: string, row: any) => {
  264. EditDialogRef.value.openDialog(type, row);
  265. };
  266. // 打开统计弹窗
  267. const onOpenStatistical = (row: any) => {
  268. statisticalDialogRef.value.openDialog(row);
  269. };
  270. // 拉黑操作
  271. const handleDelete = async (row: any) => {
  272. try {
  273. await useMessageBox().confirm('是否确认拉黑该应用');
  274. await delAppById({
  275. id: row.id,
  276. status: activeName.value == 'tab2'
  277. });
  278. ElMessage.success(activeName.value == 'tab2' ? '还原成功!' : '拉黑成功!');
  279. } catch {
  280. return;
  281. }
  282. query();
  283. };
  284. onMounted(()=>{
  285. query();
  286. })
  287. </script>
  288. <style scoped lang="scss">
  289. :deep(.el-link__inner) {
  290. display: inline-block;
  291. width: 100%;
  292. justify-content: start;
  293. }
  294. :deep(.el-link.is-underline:hover:after) {
  295. display: none;
  296. }
  297. .table-tabs {
  298. margin-bottom: 10px;
  299. }
  300. </style>