pcDiyIndex.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.name" 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-col :span="1.5">
  23. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()"> 删除 </el-button>
  24. </el-col>
  25. </el-row>
  26. </template>
  27. <el-table v-loading="loading" border :data="dataList">
  28. <el-table-column label="序号" type="index" width="70" align="center" />
  29. <el-table-column label="页面名称" align="center" prop="name" :show-overflow-tooltip="true" />
  30. <el-table-column label="页面类型" align="center" :show-overflow-tooltip="true">
  31. <template #default="scope">
  32. {{
  33. scope.row.type == 1
  34. ? '平台商城'
  35. : scope.row.type == 2
  36. ? '工业品商城'
  37. : scope.row.type == 3
  38. ? '福利商城'
  39. : scope.row.type == 4
  40. ? '客户站点商城'
  41. : scope.row.type == 5
  42. ? 'PC微页面'
  43. : ''
  44. }}
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="页面链接" align="center" prop="name">
  48. <template #default="scope">
  49. <span>/pcIndex?id={{ scope.row.id }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="状态" align="center" width="150">
  53. <template #default="scope">
  54. <el-switch @change="(status) => handleStatusChange(scope.row, status)" v-model="scope.row.isHome" :active-value="1" :inactive-value="0" />
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
  58. <template #default="scope">
  59. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">编辑</el-button>
  60. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
  65. </el-card>
  66. </div>
  67. </template>
  68. <script setup lang="ts">
  69. import { pcDiyList, pcEditDiy, pcDelDiy } from '@/api/diy/index';
  70. import { FormInstance } from 'element-plus';
  71. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  72. const dataList = ref<any[]>([]);
  73. const loading = ref(true);
  74. const multiple = ref(true);
  75. const total = ref(0);
  76. const dialogVisible = ref(false);
  77. // 添加自定义页面
  78. const formData = reactive({
  79. title: '',
  80. type: ''
  81. });
  82. // 表单验证规则
  83. const formRules = computed(() => {
  84. return {
  85. title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  86. type: [{ required: true, message: '请选择页面类型', trigger: 'blur' }]
  87. };
  88. });
  89. const queryParams = ref<any>({
  90. pageNum: 1,
  91. pageSize: 10,
  92. title: '',
  93. addon_name: '',
  94. type: 5
  95. });
  96. /** 查询字典类型列表 */
  97. const getList = () => {
  98. loading.value = true;
  99. pcDiyList(queryParams.value).then((res) => {
  100. if (res.code == 200) {
  101. dataList.value = res.rows;
  102. total.value = res.total;
  103. loading.value = false;
  104. }
  105. });
  106. };
  107. /** 表单重置 */
  108. const reset = () => {};
  109. /** 搜索按钮操作 */
  110. const handleQuery = () => {
  111. queryParams.value.pageNum = 1;
  112. getList();
  113. };
  114. /** 重置按钮操作 */
  115. const resetQuery = () => {
  116. handleQuery();
  117. };
  118. /** 新增按钮操作 */
  119. const router = useRouter();
  120. const handleAdd = () => {
  121. const url = router.resolve({
  122. path: '/diy/pcEdit',
  123. query: {
  124. type: 5,
  125. title: 'PC微页面Diy'
  126. }
  127. });
  128. window.open(url.href);
  129. };
  130. /** 修改按钮操作 */
  131. const handleUpdate = async (row?: any) => {
  132. const query = { id: row.id };
  133. const url = router.resolve({
  134. path: '/diy/pcedit',
  135. query
  136. });
  137. window.open(url.href);
  138. };
  139. /** 删除按钮操作 */
  140. const handleDelete = async (row?: any) => {
  141. await proxy?.$modal.confirm('是否确认删除"' + row.name + '"的diy数据项?').finally(() => (loading.value = false));
  142. await pcDelDiy(row.id);
  143. proxy?.$modal.msgSuccess('删除成功');
  144. getList();
  145. };
  146. const addEvent = async (formEl: FormInstance | undefined) => {
  147. if (!formEl) return;
  148. await formEl.validate(async (valid) => {
  149. if (valid) {
  150. const query = { type: formData.type, title: formData.title };
  151. const url = router.resolve({
  152. path: '/diy/pcedit',
  153. query
  154. });
  155. window.open(url.href);
  156. dialogVisible.value = false;
  157. formData.title = '';
  158. formData.type = '';
  159. }
  160. });
  161. };
  162. const handleStatusChange = async (row: any, status: any) => {
  163. const res = await pcEditDiy({
  164. id: row.id,
  165. isHome: status
  166. });
  167. if (res.code == 200) {
  168. getList();
  169. }
  170. };
  171. onMounted(() => {
  172. getList();
  173. });
  174. </script>
  175. <style lang="scss" scoped>
  176. .head-card {
  177. margin-bottom: 20px;
  178. :deep(.el-card__body) {
  179. padding-bottom: 0px !important;
  180. }
  181. }
  182. </style>