index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <el-input
  5. @keyup.enter="handleSearch"
  6. class="w200px mr5px"
  7. v-model="queryForm.keyWord"
  8. placeholder="关键字搜索"
  9. />
  10. <el-button type="primary" @click="handleSearch">
  11. <i-ep-search />
  12. 搜索
  13. </el-button>
  14. <div class="w100px ml10px" style="display: inline-block">
  15. <el-checkbox
  16. style="position: absolute; top: 11px"
  17. v-model="disableLock"
  18. label="已禁用"
  19. border
  20. ></el-checkbox>
  21. </div>
  22. <el-button @click="openDesignModule()" color="#11a983">
  23. <i-ep-plus />
  24. 增加设计模板
  25. </el-button>
  26. <el-button type="primary" @click="refreshTableInfo">
  27. <i-ep-refresh />
  28. </el-button>
  29. </div>
  30. <div class="table-con">
  31. <el-table
  32. :max-height="tableHeight"
  33. v-loading="loading"
  34. :data="tableData"
  35. highlight-current-row
  36. border
  37. >
  38. <el-table-column label="操作" width="250">
  39. <template #default="{ row }">
  40. <el-button link @click="openDesignModule(row.id)" type="primary">
  41. <i-ep-edit />
  42. 编辑
  43. </el-button>
  44. <el-button link @click="openDialog(row.id)" type="info">
  45. <i-ep-edit />
  46. 缩略图
  47. </el-button>
  48. <el-button
  49. v-if="row.voidFlag == 0"
  50. link
  51. @click="handleDisable(row.id, 1)"
  52. type="warning"
  53. >禁用
  54. </el-button>
  55. <el-button
  56. v-if="row.voidFlag == 1"
  57. type="success"
  58. link
  59. @click="handleDisable(row.id, 0)"
  60. >启用
  61. </el-button>
  62. </template>
  63. </el-table-column>
  64. <el-table-column type="index" label="#" width="50">
  65. <template #default="scope">
  66. <span>{{ scope.$index + 1 }}</span>
  67. </template>
  68. </el-table-column>
  69. <el-table-column prop="templateName" label="模板名称" />
  70. <el-table-column prop="viewThumbPath" width="320" label="缩略图">
  71. <template #default="{ row }">
  72. <el-image
  73. style="width: 200px; height: 200px"
  74. :src="row.viewThumbPath"
  75. fit="contain"
  76. />
  77. </template>
  78. </el-table-column>
  79. <el-table-column prop="voidFlag" width="120" label="状态">
  80. <template #default="{ row }">
  81. <el-tag v-if="row.voidFlag == 0" type="success"> 正常</el-tag>
  82. <el-tag v-else="row.voidFlag == 1" type="danger"> 停用</el-tag>
  83. </template>
  84. </el-table-column>
  85. <el-table-column prop="canvasHeight" width="150" label="画布高(mm)" />
  86. <el-table-column prop="canvasWidth" width="150" label="画布宽(mm)" />
  87. <el-table-column prop="createTime" label="创建时间" width="155">
  88. <template #default="{ row }">
  89. <span v-if="row.createTime">
  90. {{ $filters.getTime(row.createTime) }}
  91. </span>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. <pagination
  96. v-if="total > 0"
  97. v-model:total="total"
  98. v-model:page="queryPage.pageIndex"
  99. v-model:limit="queryPage.pageSize"
  100. @pagination="getTableData"
  101. />
  102. </div>
  103. <child-dialog ref="childDialog" @dialogChange="dialogChange"></child-dialog>
  104. </div>
  105. </template>
  106. <script setup lang="ts">
  107. import { useTable } from "@/hooks/useTable";
  108. import {
  109. queryDesignTemplates,
  110. saveCurrentUserTokenInfo,
  111. voidDesignTemplate,
  112. } from "@/api/design";
  113. import ChildDialog from "./compt/childDialog.vue";
  114. const childDialog = ref<any>();
  115. const disableLock = ref("");
  116. function generateUUID() {
  117. return "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function (c) {
  118. var r = (Math.random() * 16) | 0,
  119. v = c == "x" ? r : (r & 0x3) | 0x8;
  120. return v.toString(16);
  121. });
  122. }
  123. //增加编辑
  124. function openDialog(item?: any) {
  125. childDialog.value.dialogVisible = true;
  126. if (item) {
  127. childDialog.value.dialogTitle = "编辑";
  128. nextTick(() => {
  129. childDialog.value.getItemData(item);
  130. });
  131. }
  132. }
  133. function openDesignModule(item?: any) {
  134. //todo 转跳外部模板编辑地址
  135. const param = {
  136. virtualCode: generateUUID(),
  137. };
  138. saveCurrentUserTokenInfo(param).then((response) => {
  139. if (response.httpCode == 200) {
  140. if (item) {
  141. window.open("http://192.168.1.44:9191/?virtualCode=" + param.virtualCode + "&template=" + item, "_blank");
  142. } else {
  143. window.open("http://192.168.1.44:9191/?virtualCode=" + param.virtualCode, "_blank");
  144. }
  145. }
  146. });
  147. }
  148. //禁用删除
  149. function handleDisable(id, status) {
  150. ElMessageBox.confirm("确认操作?", "警告", {
  151. confirmButtonText: "确定",
  152. cancelButtonText: "取消",
  153. type: "warning",
  154. }).then(() => {
  155. const postData = {
  156. id: id,
  157. voidFlag: status,
  158. };
  159. const params = {
  160. template: JSON.stringify(postData),
  161. };
  162. voidDesignTemplate(params).then((response) => {
  163. if (response.httpCode == 200) {
  164. ElMessage.success("操作成功");
  165. getTableData();
  166. }
  167. });
  168. });
  169. }
  170. //修改成功后传递事件
  171. function dialogChange() {
  172. getTableData();
  173. }
  174. const queryForm = reactive({
  175. keyWord: "",
  176. voidFlag: 0,
  177. });
  178. watch(
  179. () => disableLock.value,
  180. (disableLock) => {
  181. console.log(disableLock);
  182. if (disableLock) {
  183. queryForm.voidFlag = 1;
  184. getTableData();
  185. } else {
  186. queryForm.voidFlag = 0;
  187. getTableData();
  188. }
  189. }
  190. );
  191. const {
  192. tableData,
  193. queryPage,
  194. total,
  195. loading,
  196. getTableData,
  197. tableHeight,
  198. handleSearch, //搜索
  199. refreshTableInfo, //刷新
  200. } = useTable(queryDesignTemplates, queryForm);
  201. </script>