miniTemplate.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div class="p-2">
  3. <div class="head-card">
  4. <el-card shadow="hover">
  5. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  6. <el-form-item label="模板名称">
  7. <el-input v-model="queryParams.title" placeholder="请输入模板名称" clearable @keyup.enter="handleQuery" />
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  11. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  12. </el-form-item>
  13. </el-form>
  14. </el-card>
  15. </div>
  16. <el-card shadow="hover">
  17. <template #header>
  18. <el-row :gutter="10" class="mb8">
  19. <el-col :span="1.5">
  20. <el-button type="primary" plain icon="Plus" @click="handleAdd">添加模板</el-button>
  21. </el-col>
  22. </el-row>
  23. </template>
  24. <el-table v-loading="loading" border :data="dataList">
  25. <el-table-column label="模板名称" align="center" prop="name" :show-overflow-tooltip="true" />
  26. <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
  27. <template #default="scope">
  28. <el-tooltip content="修改" placement="top">
  29. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
  30. </el-tooltip>
  31. <el-tooltip content="删除" placement="top">
  32. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
  33. </el-tooltip>
  34. </template>
  35. </el-table-column>
  36. </el-table>
  37. <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
  38. </el-card>
  39. <!--添加页面-->
  40. <el-dialog v-model="dialogVisible" title="创建新模板" width="1122px">
  41. <div class="card-container">
  42. <div
  43. v-for="(item, index) in dialogList"
  44. @click="onDialog(item)"
  45. :key="index"
  46. class="card-item"
  47. :class="{ active: dialogType === item.diyType }"
  48. >
  49. <div class="card-image">
  50. <img :src="item.img" alt="图片" />
  51. </div>
  52. <div class="card-text">{{ item.title }}</div>
  53. </div>
  54. </div>
  55. <template #footer>
  56. <span class="dialog-footer">
  57. <el-button @click="dialogVisible = false">取消</el-button>
  58. <el-button type="primary" @click="addEvent()">确认</el-button>
  59. </span>
  60. </template>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script setup lang="ts">
  65. import { miniList, delMin, template } from '@/api/diy/index';
  66. import { FormInstance } from 'element-plus';
  67. import diy1 from '@/assets/images/diy/diy1.jpg';
  68. import diy2 from '@/assets/images/diy/diy2.jpg';
  69. import diy3 from '@/assets/images/diy/diy3.jpg';
  70. import diy4 from '@/assets/images/diy/diy4.png';
  71. import diy5 from '@/assets/images/diy/diy5.jpg';
  72. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  73. const dataList = ref<any[]>([]);
  74. const loading = ref(true);
  75. const total = ref(0);
  76. const dialogType = ref();
  77. const dialogList = ref<any>([
  78. { title: '首页模板', diyType: 1, img: diy1 },
  79. { title: '个人中心模板', diyType: 2, img: diy3 },
  80. { title: '商品详情模板', diyType: 3, img: diy4 }
  81. ]);
  82. const pageType: any = reactive({}); // 页面类型
  83. const dialogVisible = ref(false);
  84. const formRef = ref<FormInstance>();
  85. // 添加自定义页面
  86. const formData = reactive({
  87. title: '',
  88. type: ''
  89. });
  90. // 表单验证规则
  91. const formRules = computed(() => {
  92. return {
  93. title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  94. type: [{ required: true, message: '请选择页面类型', trigger: 'blur' }]
  95. };
  96. });
  97. const queryParams = ref<any>({
  98. pageNum: 1,
  99. pageSize: 10,
  100. title: '',
  101. addon_name: '',
  102. type: ''
  103. });
  104. /** 查询字典类型列表 */
  105. const getList = () => {
  106. loading.value = true;
  107. miniList(queryParams.value).then((res) => {
  108. if (res.code == 200) {
  109. dataList.value = res.rows;
  110. total.value = res.total;
  111. loading.value = false;
  112. }
  113. });
  114. };
  115. /** 搜索按钮操作 */
  116. const handleQuery = () => {
  117. queryParams.value.pageNum = 1;
  118. getList();
  119. };
  120. /** 重置按钮操作 */
  121. const resetQuery = () => {
  122. handleQuery();
  123. };
  124. /** 新增按钮操作 */
  125. const router = useRouter();
  126. const handleAdd = () => {
  127. dialogVisible.value = true;
  128. // const url = router.resolve({
  129. // path: '/diy/edit',
  130. // query: {}
  131. // });
  132. // window.open(url.href);
  133. };
  134. /** 修改按钮操作 */
  135. const handleUpdate = async (row?: any) => {
  136. const query = { id: row.id };
  137. const url = router.resolve({
  138. path: '/diy/miniEdit',
  139. query
  140. });
  141. window.open(url.href);
  142. };
  143. /** 删除按钮操作 */
  144. const handleDelete = async (row?: any) => {
  145. await proxy?.$modal.confirm('是否确认删除"' + row.name + '"的diy数据项?').finally(() => (loading.value = false));
  146. await delMin(row.id);
  147. proxy?.$modal.msgSuccess('删除成功');
  148. getList();
  149. };
  150. const getTemplate = () => {
  151. template({ mode: '', addon: '' }).then((res) => {
  152. if (res.code == 200) {
  153. for (const key in pageType) {
  154. delete pageType[key];
  155. }
  156. for (const key in res.data) {
  157. pageType[key] = res.data[key];
  158. }
  159. }
  160. });
  161. };
  162. const addEvent = () => {
  163. const obj = dialogList.value.find((item: any) => item.diyType == dialogType.value);
  164. const query = { type: obj.diyType, title: obj.title };
  165. const url = router.resolve({
  166. path: '/diy/miniEdit',
  167. query
  168. });
  169. window.open(url.href);
  170. dialogVisible.value = false;
  171. };
  172. // const addEvent = async (formEl: FormInstance | undefined) => {
  173. // if (!formEl) return;
  174. // await formEl.validate(async (valid) => {
  175. // if (valid) {
  176. // const query = { type: formData.type, title: formData.title };
  177. // const url = router.resolve({
  178. // path: '/diy/edit',
  179. // query
  180. // });
  181. // window.open(url.href);
  182. // dialogVisible.value = false;
  183. // formData.title = '';
  184. // formData.type = '';
  185. // }
  186. // });
  187. // };
  188. const onDialog = (item: any) => {
  189. dialogType.value = item.diyType;
  190. };
  191. onMounted(() => {
  192. getList();
  193. getTemplate();
  194. });
  195. </script>
  196. <style lang="scss" scoped>
  197. .head-card {
  198. margin-bottom: 20px;
  199. :deep(.el-card__body) {
  200. padding-bottom: 0px !important;
  201. }
  202. }
  203. .card-container {
  204. display: flex;
  205. flex-wrap: wrap;
  206. gap: 0 15px;
  207. width: 1060px;
  208. .card-item {
  209. width: 200px;
  210. height: 390px;
  211. padding: 5px;
  212. border-radius: 8px;
  213. border: 1px solid #e5e7eb;
  214. cursor: pointer;
  215. transition: all 0.3s ease;
  216. position: relative;
  217. &:hover {
  218. border-color: #b0b0b0;
  219. }
  220. &.active {
  221. border-color: #409eff;
  222. background-color: #ecf5ff;
  223. }
  224. .card-image {
  225. width: 190px;
  226. height: 340px;
  227. overflow: hidden;
  228. border-radius: 4px;
  229. img {
  230. width: 100%;
  231. height: 100%;
  232. object-fit: cover;
  233. }
  234. }
  235. .card-text {
  236. width: 190px;
  237. bottom: 0;
  238. left: 0;
  239. font-size: 14px;
  240. color: #333;
  241. text-align: center;
  242. white-space: nowrap;
  243. overflow: hidden;
  244. text-overflow: ellipsis;
  245. text-align: center;
  246. margin-top: 20px;
  247. }
  248. }
  249. }
  250. </style>