index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div class="search" v-show="showSearch">
  5. <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
  6. <el-form-item label="应用名称" prop="applicationName">
  7. <el-input v-model="queryParams.applicationName" placeholder="请输入应用名称" clearable style="width: 240px" @keyup.enter="handleQuery" />
  8. </el-form-item>
  9. <el-form-item label="图标" prop="icon">
  10. <el-input v-model="queryParams.icon" placeholder="请输入图标" clearable style="width: 240px" @keyup.enter="handleQuery" />
  11. </el-form-item>
  12. <el-form-item label="跳转地址" prop="url">
  13. <el-input v-model="queryParams.url" placeholder="请输入跳转地址" clearable style="width: 240px" @keyup.enter="handleQuery" />
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  17. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  18. </el-form-item>
  19. </el-form>
  20. </div>
  21. </transition>
  22. <el-tabs v-model="activeTab" style="padding: 5px;">
  23. <el-tab-pane label="千寻应用" name="tab1">
  24. <el-card shadow="never">
  25. <template #header>
  26. <el-row :gutter="10" class="mb8">
  27. <el-col :span="1.5">
  28. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['smarttrace:application:add']">新增</el-button>
  29. </el-col>
  30. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  31. </el-row>
  32. </template>
  33. <el-table v-loading="loading" :data="applicationList" border>
  34. <el-table-column type="index" label="序号" width="55" align="center" />
  35. <el-table-column label="应用名称" align="center" prop="applicationName" />
  36. <el-table-column label="图标" align="center" prop="icon">
  37. <template #default="{ row }">
  38. <ImagePreview :src="row.icon" style="width: 50px;height: 50px;"></ImagePreview>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="背景" align="center" prop="bgUrl">
  42. <template #default="{ row }">
  43. <ImagePreview :src="row.bgUrl" style="width: 50px;height: 50px;"></ImagePreview>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="跳转地址" align="center" prop="url" />
  47. <el-table-column label="应用类型" align="center" prop="type">
  48. <template #default="{ row }">
  49. <span>{{ selectDictLabel(application_type, row.type) }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="前置条件" width="200">
  53. <template #default="{ row }">
  54. <div v-for="item in row.precondition" style="display: flex;">
  55. <div>
  56. <dict-tag :options="enterprise_type" :value="item.cpyType" />
  57. </div>
  58. -
  59. <div>
  60. <dict-tag :options="industry_type" :value="item.industryType" />
  61. </div>
  62. </div>
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="状态" align="center" width="180" prop="status">
  66. <template #default="{ row }">
  67. <el-switch v-model="row.status" active-value="1" @change="changeStatus($event, row.id)" inactive-value="0" active-text="启用" inactive-text="未启用" />
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="备注" align="center" prop="remark" />
  71. <el-table-column label="应用ID" align="center" prop="id" />
  72. <el-table-column label="创建时间" align="center" prop="createTime" width="120">
  73. <template #default="scope">
  74. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
  78. <template #default="scope">
  79. <el-tooltip content="编辑" placement="top">
  80. <el-button link type="primary" icon="Edit" @click="handleEdit(scope.row)" v-hasPermi="['smarttrace:application:remove']"></el-button>
  81. </el-tooltip>
  82. <el-tooltip content="删除" placement="top">
  83. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['smarttrace:application:remove']"></el-button>
  84. </el-tooltip>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  89. </el-card>
  90. </el-tab-pane>
  91. <el-tab-pane label="合作伙伴应用" name="tab2">
  92. <el-table v-loading="loading" :data="applicationList2" border>
  93. <el-table-column type="index" width="55" align="center" label="序号" />
  94. <el-table-column label="应用名称" align="center" prop="applicationName" />
  95. <el-table-column label="图标" align="center" prop="icon">
  96. <template #default="{ row }">
  97. <ImagePreview :src="row.icon" style="width: 50px;height: 50px;"></ImagePreview>
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="背景" align="center" prop="bgUrl">
  101. <template #default="{ row }">
  102. <ImagePreview :src="row.bgUrl" style="width: 50px;height: 50px;"></ImagePreview>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="跳转地址" align="center" prop="url" />
  106. <el-table-column label="应用类型" align="center" prop="type">
  107. <template #default="{ row }">
  108. <span>{{ selectDictLabel(application_type, row.type) }}</span>
  109. </template>
  110. </el-table-column>
  111. <el-table-column label="状态" align="center" width="180" prop="status">
  112. <template #default="{ row }">
  113. <el-switch v-model="row.status" active-value="1" inactive-value="0" disabled active-text="启用" inactive-text="未启用" />
  114. </template>
  115. </el-table-column>
  116. <el-table-column label="备注" align="center" prop="remark" />
  117. <el-table-column label="应用ID" align="center" prop="id" />
  118. <el-table-column label="授权开始日期" align="center" prop="startAt" />
  119. <el-table-column label="授权结束日期" align="center" prop="endAt" />
  120. <el-table-column label="千寻应用" align="center" prop="originName" />
  121. <el-table-column label="合作伙伴" align="center" prop="partner">
  122. <template #default="{ row }"></template>
  123. </el-table-column>
  124. <el-table-column label="创建时间" align="center" prop="createTime" width="120">
  125. <template #default="scope">
  126. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  127. </template>
  128. </el-table-column>
  129. </el-table>
  130. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList2" />
  131. </el-tab-pane>
  132. </el-tabs>
  133. <!-- 添加或修改应用信息对话框 -->
  134. <el-dialog :close-on-click-modal="false" :title="dialog.title" v-model="dialog.visible" width="600px" append-to-body>
  135. <el-form ref="applicationFormRef" :model="form" :rules="rules" label-width="80px">
  136. <el-row>
  137. <el-col :span="12">
  138. <el-form-item label="应用名称" prop="applicationName">
  139. <el-input v-model="form.applicationName" placeholder="请输入应用名称" />
  140. </el-form-item>
  141. </el-col>
  142. <el-col :span="12">
  143. <el-form-item label="应用类型" prop="type">
  144. <el-select v-model="form.type" style="width: 100%;" placeholder="请选择应用类型" clearable>
  145. <el-option v-for="dict in application_type" :key="dict.value" :label="dict.label" :value="dict.value" />
  146. </el-select>
  147. </el-form-item>
  148. </el-col>
  149. </el-row>
  150. <el-row>
  151. <el-col :span="12">
  152. <el-form-item label="图标" prop="icon">
  153. <div>
  154. <UploadAvatar title="应用图标" v-model="form.icon"></UploadAvatar>
  155. </div>
  156. </el-form-item>
  157. </el-col>
  158. <el-col :span="12">
  159. <el-form-item label="背景" prop="bgUrl">
  160. <div class="flex1">
  161. <PhotoUpload v-model="form.bgUrl"></PhotoUpload>
  162. </div>
  163. </el-form-item>
  164. </el-col>
  165. </el-row>
  166. <el-form-item label="排序" prop="sort">
  167. <el-input-number v-model="form.sort" placeholder="请输入排序" />
  168. </el-form-item>
  169. <el-form-item label="按钮配置" prop="btnConf">
  170. <el-input v-model="form.btnConf" placeholder="请输入按钮配置" />
  171. </el-form-item>
  172. <el-form-item label="跳转地址" prop="url">
  173. <el-input v-model="form.url" placeholder="请输入跳转地址" />
  174. </el-form-item>
  175. <el-form-item label="备注" prop="remark">
  176. <el-input v-model="form.remark" placeholder="请输入备注" />
  177. </el-form-item>
  178. <el-divider>前置条件(任意一个)</el-divider>
  179. <div class="cpy-container" v-loading="loading">
  180. <div class="cpy-item" v-for="(item, index) in form.precondition" :key="index">
  181. <el-form-item label="企业类型" :prop="`precondition.${index}.cpyType`" :rules="{ required: true, message: '企业类型不能为空', trigger: 'blur' }">
  182. <el-select v-model="item.cpyType" placeholder="企业类型" clearable>
  183. <el-option v-for="dict in enterprise_type" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
  184. </el-select>
  185. </el-form-item>
  186. <el-form-item label="行业类别" :prop="`precondition.${index}.industryType`" :rules="{ required: true, message: '行业类别不能为空', trigger: 'blur' }" clearable>
  187. <el-select v-model="item.industryType" placeholder="行业类别">
  188. <el-option v-for="dict in industry_type" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
  189. </el-select>
  190. </el-form-item>
  191. <el-button type="text" icon="remove" @click="handleRemovePrecondition(index)"></el-button>
  192. </div>
  193. </div>
  194. <span v-show="form.precondition.length == 0">无需前置条件</span>
  195. <div style="display: flex;">
  196. <el-button type="primary" style="flex:1" @click="handleAddPrecondition">添加条件</el-button>
  197. </div>
  198. </el-form>
  199. <template #footer>
  200. <div class="dialog-footer">
  201. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  202. <el-button @click="cancel">取 消</el-button>
  203. </div>
  204. </template>
  205. </el-dialog>
  206. </div>
  207. </template>
  208. <script setup name="Application" lang="ts">
  209. import { listApplicationQx, listApplicationOther, getApplication, delApplication, addApplication, updateApplication, ApplicationOnshelf, ApplicationLeaveshelf } from '@/api/permission/application';
  210. import { ApplicationVO, ApplicationQuery, ApplicationForm } from '@/api/permission/application/types';
  211. import { UploadAvatar } from '@/views/components';
  212. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  213. const { application_type, enterprise_type, industry_type } = toRefs<any>(proxy?.useDict('application_type', 'industry_type', 'enterprise_type'));
  214. const applicationList = ref<ApplicationVO[]>([]);
  215. const buttonLoading = ref(false);
  216. const loading = ref(true);
  217. const showSearch = ref(true);
  218. const ids = ref<Array<string | number>>([]);
  219. const total = ref(0);
  220. const queryFormRef = ref<ElFormInstance>();
  221. const applicationFormRef = ref<ElFormInstance>();
  222. const dialog = reactive<DialogOption>({
  223. visible: false,
  224. title: ''
  225. });
  226. const initFormData = (): ApplicationForm => ({
  227. id: undefined,
  228. applicationName: undefined,
  229. icon: undefined,
  230. url: undefined,
  231. type: undefined,
  232. remark: undefined,
  233. keyInfo: {},
  234. sort: 0,
  235. btnConf: undefined,
  236. precondition: []
  237. });
  238. const data = reactive<PageData<ApplicationForm, ApplicationQuery>>({
  239. form: initFormData(),
  240. queryParams: {
  241. pageNum: 1,
  242. pageSize: 10,
  243. applicationName: undefined,
  244. type: undefined,
  245. status: undefined,
  246. params: {}
  247. },
  248. rules: {
  249. applicationName: [{ required: true, message: '应用名称不能为空', trigger: 'blur' }],
  250. icon: [{ required: true, message: '图标不能为空', trigger: 'blur' }],
  251. url: [{ required: true, message: '跳转地址不能为空', trigger: 'blur' }],
  252. type: [{ required: true, message: '应用类型不能为空', trigger: 'change' }]
  253. }
  254. });
  255. const { queryParams, form, rules } = toRefs(data);
  256. /** 启用和未启用开关 */
  257. const changeStatus = async (event: string, id: string) => {
  258. let res = null;
  259. loading.value = true;
  260. if (+event) {
  261. res = await ApplicationOnshelf(id);
  262. } else {
  263. res = await ApplicationLeaveshelf(id);
  264. }
  265. getList();
  266. };
  267. /** 查询应用信息列表 */
  268. const getList = async () => {
  269. loading.value = true;
  270. const res = await listApplicationQx(queryParams.value);
  271. applicationList.value = res.rows;
  272. total.value = res.total;
  273. loading.value = false;
  274. };
  275. /** 取消按钮 */
  276. const cancel = () => {
  277. reset();
  278. dialog.visible = false;
  279. };
  280. /** 表单重置 */
  281. const reset = () => {
  282. form.value = initFormData();
  283. applicationFormRef.value?.resetFields();
  284. };
  285. /** 搜索按钮操作 */
  286. const handleQuery = () => {
  287. queryParams.value.pageNum = 1;
  288. queryParams2.value.pageNum = 1;
  289. getList();
  290. getList2();
  291. };
  292. /** 重置按钮操作 */
  293. const resetQuery = () => {
  294. queryFormRef.value?.resetFields();
  295. handleQuery();
  296. };
  297. /** 添加前置条件 */
  298. const handleAddPrecondition = () => {
  299. form.value.precondition.push({ cpyType: undefined, industryType: undefined });
  300. };
  301. const handleRemovePrecondition = (index: number) => {
  302. form.value.precondition.splice(index, 1);
  303. };
  304. /** 新增按钮操作 */
  305. const handleAdd = () => {
  306. reset();
  307. dialog.visible = true;
  308. dialog.title = '添加应用信息';
  309. };
  310. const handleEdit = (row: any) => {
  311. reset();
  312. Object.assign(form.value, row);
  313. dialog.visible = true;
  314. dialog.title = '修改应用信息';
  315. };
  316. /** 提交按钮 */
  317. const submitForm = () => {
  318. applicationFormRef.value?.validate(async (valid: boolean) => {
  319. if (valid) {
  320. buttonLoading.value = true;
  321. if (form.value.id) {
  322. await updateApplication(form.value).finally(() => (buttonLoading.value = false));
  323. } else {
  324. await addApplication(form.value).finally(() => (buttonLoading.value = false));
  325. }
  326. proxy?.$modal.msgSuccess('修改成功');
  327. dialog.visible = false;
  328. await getList();
  329. }
  330. });
  331. };
  332. /** 删除按钮操作 */
  333. const handleDelete = async (row?: ApplicationVO) => {
  334. const _ids = row?.id || ids.value;
  335. await proxy?.$modal.confirm('是否确认删除应用信息编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
  336. await delApplication(_ids);
  337. proxy?.$modal.msgSuccess('删除成功');
  338. await getList();
  339. };
  340. /**合作伙伴应用 */
  341. const activeTab = ref('tab1');
  342. const applicationList2 = ref<ApplicationVO[]>([]);
  343. const queryParams2 = ref<ApplicationQuery>({
  344. pageNum: 1,
  345. pageSize: 10,
  346. applicationName: undefined,
  347. type: undefined,
  348. status: undefined
  349. });
  350. watch(queryParams, (newValue) => {
  351. queryParams2.value.applicationName = newValue.applicationName;
  352. queryParams2.value.type = newValue.type;
  353. queryParams2.value.status = newValue.status;
  354. });
  355. const total2 = ref(0);
  356. const loading2 = ref(false);
  357. /** 查询合作伙伴应用信息列表 */
  358. const getList2 = async () => {
  359. loading2.value = true;
  360. const res = await listApplicationOther(queryParams2.value);
  361. applicationList2.value = res.rows;
  362. total2.value = res.total;
  363. loading2.value = false;
  364. };
  365. onMounted(() => {
  366. getList();
  367. getList2();
  368. });
  369. </script>
  370. <style scoped>
  371. .cpy-container {
  372. margin-top: 20px;
  373. margin-bottom: 20px;
  374. .cpy-item {
  375. display: flex;
  376. justify-content: space-between;
  377. align-items: baseline;
  378. }
  379. }
  380. </style>