index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="page">
  3. <el-card shadow="never">
  4. <div class="search">
  5. <el-form inline>
  6. <!-- 关键字 -->
  7. <el-form-item :label="$t('message.device.formI18nLabel.keyword')">
  8. <el-input v-model="searchParams.keyWord" style="width: 200px; margin-left: 20px" class="search-input" :placeholder="$t('message.configuration.designScreen.keywordPlaceholder')" clearable @keyup.enter="handleSearch" />
  9. </el-form-item>
  10. <el-form-item>
  11. <!-- 查询 -->
  12. <el-button type="primary" @click="handleSearch">
  13. <el-icon><ele-Search /></el-icon>
  14. {{ $t('message.formI18nButton.query') }}
  15. </el-button>
  16. </el-form-item>
  17. <el-form-item>
  18. <!-- 新增大屏 -->
  19. <el-button type="primary" v-auth="'add'" @click="addOrEdit()">
  20. <el-icon>
  21. <ele-FolderAdd />
  22. </el-icon>
  23. {{ $t('message.configuration.designScreen.addScreen') }}
  24. </el-button>
  25. </el-form-item>
  26. </el-form>
  27. </div>
  28. <el-table :data="tableData" style="width: 100%" v-loading="loading">
  29. <!-- 序号 -->
  30. <el-table-column type="index" :label="$t('message.tableI18nColumn.index')" width="70" align="center" />
  31. <!-- ID -->
  32. <el-table-column prop="id" :label="$t('message.tableI18nColumn.id')" show-overflow-tooltip></el-table-column>
  33. <!-- 大屏名称 -->
  34. <el-table-column prop="projectName" :label="$t('message.configuration.designScreen.screenName')" show-overflow-tooltip></el-table-column>
  35. <!-- 描述 -->
  36. <el-table-column prop="remarks" :label="$t('message.tableI18nColumn.des')" show-overflow-tooltip></el-table-column>
  37. <!-- 创建时间 -->
  38. <el-table-column prop="createdAt" :label="$t('message.tableI18nColumn.createdAt')" min-width="100" align="center"></el-table-column>
  39. <!-- 更新时间 -->
  40. <el-table-column prop="updatedAt" :label="$t('message.tableI18nColumn.updatedAt')" min-width="100" align="center"></el-table-column>
  41. <!-- 操作 -->
  42. <el-table-column :label="$t('message.tableI18nColumn.operation')" width="200" align="center">
  43. <template #default="scope">
  44. <!-- 预览 -->
  45. <el-button size="small" text type="primary" @click="preview(scope.row)">{{ $t('message.configuration.designScreen.previewBtn') }}</el-button>
  46. <!-- 编辑 -->
  47. <el-button size="small" text type="warning" v-auth="'edit'" @click="addOrEdit(scope.row)">{{ $t('message.tableI18nAction.edit') }}</el-button>
  48. <!-- 设计大屏 -->
  49. <el-button size="small" text type="warning" @click="edit(scope.row)">{{ $t('message.configuration.designScreen.designBtn') }}</el-button>
  50. <!-- 删除 -->
  51. <el-button size="small" text type="info" v-auth="'del'" @click="onDel(scope.row)">{{ $t('message.tableI18nAction.delete') }}</el-button>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
  56. <EditForm ref="editFormRef" @getList="getList(1)"></EditForm>
  57. </el-card>
  58. </div>
  59. </template>
  60. <script lang="ts" setup>
  61. import { ref, reactive, watch } from 'vue';
  62. import api from '/@/api/screen';
  63. import { ElMessageBox, ElMessage } from 'element-plus';
  64. import { useSearch } from '/@/hooks/useCommon';
  65. import EditForm from './edit.vue';
  66. import { useI18n } from 'vue-i18n';
  67. // 国际化
  68. const { t } = useI18n();
  69. const editFormRef = ref();
  70. const searchParams = reactive({
  71. keyWord: ''
  72. });
  73. // 监听搜索参数变化,确保在API请求中正确传递搜索条件
  74. watch(searchParams, (newVal:any) => {
  75. // 处理搜索参数的值
  76. for (const key in newVal) {
  77. if (newVal[key] === '' || newVal[key] === null) {
  78. delete params[key];
  79. } else {
  80. params[key] = newVal[key];
  81. }
  82. }
  83. }, { deep: true });
  84. const { params, tableData, getList, loading } = useSearch<any[]>(api.getList, 'Data', searchParams);
  85. getList();
  86. // 搜索
  87. const handleSearch = () => {
  88. getList(1);
  89. };
  90. const addOrEdit = async (row?: any) => {
  91. if (row) {
  92. editFormRef.value.open(row);
  93. return;
  94. } else {
  95. editFormRef.value.open();
  96. }
  97. };
  98. // const add = async () => {
  99. // ElMessageBox.prompt('请输入项目名称', '创建大屏项目', {
  100. // confirmButtonText: '确认',
  101. // cancelButtonText: '取消',
  102. // inputValidator: (value: string) => {
  103. // if (value.trim()) {
  104. // return true;
  105. // } else {
  106. // return '请输入项目名称';
  107. // }
  108. // },
  109. // inputErrorMessage: '请输入描述',
  110. // }).then(async ({ value: projectName }) => {
  111. // ElMessageBox.prompt('请输入描述', '创建大屏项目', {
  112. // confirmButtonText: '确认',
  113. // cancelButtonText: '取消',
  114. // }).then(async ({ value: remarks }) => {
  115. // await api.add({
  116. // indexImage: null,
  117. // projectName,
  118. // remarks,
  119. // });
  120. // ElMessage.success('新增成功');
  121. // getList();
  122. // });
  123. // });
  124. // };
  125. const edit = async (row: any) => {
  126. const url = import.meta.env.VITE_SCREEN_URL + '#/chart/home/' + row.id;
  127. window.open(url);
  128. };
  129. const preview = async (row: any) => {
  130. const url = import.meta.env.VITE_SCREEN_URL + '#/chart/preview/' + row.id;
  131. window.open(url);
  132. };
  133. const onDel = (row: any) => {
  134. ElMessageBox.confirm(
  135. t('message.configuration.designScreen.deleteScreenMessage', { name: row.projectName }),
  136. t('message.tableI18nConfirm.deleteTitle'), {
  137. confirmButtonText: t('message.tableI18nConfirm.confirmText'),
  138. cancelButtonText: t('message.tableI18nConfirm.cancelText'),
  139. type: 'warning',
  140. }).then(async () => {
  141. await api.del([row.id as string]);
  142. ElMessage.success(t('message.tableI18nConfirm.deleteSuccess'));
  143. getList();
  144. });
  145. };
  146. </script>