|
@@ -1,8 +1,7 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<el-card>
|
|
|
- <el-button type="primary"
|
|
|
- @click="() => router.push({ path: '/product/add'})">添加产品服务
|
|
|
+ <el-button type="primary" @click="() => router.push({ path: '/product/add' })">添加产品服务
|
|
|
</el-button>
|
|
|
<!-- 添加el-dialog组件 -->
|
|
|
<el-table :data="tableData" border style="width: 100%;margin-top:20px">
|
|
@@ -23,13 +22,8 @@
|
|
|
</el-table-column>
|
|
|
<el-table-column prop="title" label="是否首页显示" width="180">
|
|
|
<template #default="scope">
|
|
|
- <el-switch
|
|
|
- v-model="scope.row.isIndex"
|
|
|
- size="large"
|
|
|
- active-text="显示"
|
|
|
- inactive-text="不显示"
|
|
|
- @change="handleSwitchChange(scope.row)"
|
|
|
- />
|
|
|
+ <el-switch v-model="scope.row.isIndex" size="large" active-text="显示" inactive-text="不显示"
|
|
|
+ @change="updateProducts(scope.row)" />
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
<el-table-column prop="ptype" label="产品类型" width="180">
|
|
@@ -47,7 +41,7 @@
|
|
|
<el-button type="danger" size="small" @click="deleteProduct(scope.row.ID)">删除</el-button>
|
|
|
<!-- <el-button type="primary" size="small" @click="deleteResource(scope.row.ID)">修改</el-button>-->
|
|
|
<el-button size="small"
|
|
|
- @click="() => router.push({ path: '/product/detail', query: { id: scope.row.ID } })">
|
|
|
+ @click="() => router.push({ path: '/product/detail', query: { id: scope.row.ID } })">
|
|
|
详情
|
|
|
</el-button>
|
|
|
</template>
|
|
@@ -55,19 +49,18 @@
|
|
|
</el-table>
|
|
|
<!-- 分页 -->
|
|
|
<el-pagination style="margin-top:20px" :current-page="searchForm.page" :page-size="searchForm.size"
|
|
|
- :total="total"
|
|
|
- @current-change="handleCurrentChange"/>
|
|
|
+ :total="total" @current-change="handleCurrentChange" />
|
|
|
</el-card>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import {onMounted, reactive, ref} from "vue";
|
|
|
-import {ElMessage, ElMessageBox} from 'element-plus';
|
|
|
-import {useRouter} from 'vue-router'
|
|
|
+import { onMounted, reactive, ref } from "vue";
|
|
|
+import { ElMessage, ElMessageBox } from 'element-plus';
|
|
|
+import { useRouter } from 'vue-router'
|
|
|
import resource from "../../api/resource";
|
|
|
import product from "../../api/product.js";
|
|
|
-
|
|
|
+const isIndex = ref(false)
|
|
|
const router = useRouter();
|
|
|
// Dom 挂载之后
|
|
|
onMounted(() => {
|
|
@@ -113,7 +106,7 @@ const toggleUpload = () => {
|
|
|
// 搜索条件
|
|
|
const searchForm = reactive({
|
|
|
page: 1,
|
|
|
- size: 5,
|
|
|
+ size: 10,
|
|
|
desc: 'created_at desc'
|
|
|
})
|
|
|
// 获取资源列表
|
|
@@ -122,26 +115,16 @@ const getProductAll = async () => {
|
|
|
tableData.value = res.data.Data.Data;
|
|
|
total.value = res.data.Data.Size;
|
|
|
}
|
|
|
-const handleSwitchChange = async (row) => {
|
|
|
- try {
|
|
|
- // 这里根据实际情况调用你的修改方法,例如 updateProduct
|
|
|
- await updateProduct(row.ID, row.isIndex);
|
|
|
- await getProductAll();
|
|
|
- } catch (error) {
|
|
|
- ElMessage.error('更新状态时出错');
|
|
|
- }
|
|
|
-}
|
|
|
-const updateProduct = async (id, isIndex) => {
|
|
|
- const res = await product.updateProduct({id: id, isIndex: isIndex});
|
|
|
+const updateProducts = async (row) => {
|
|
|
+ const res = await product.updateProduct({ id: row.ID, isIndex: row.isIndex });
|
|
|
if (res.data.Code === 200) {
|
|
|
ElMessage.success("修改成功")
|
|
|
- await getProductAll();
|
|
|
+ // await getProductAll();
|
|
|
} else {
|
|
|
ElMessage.error(res.data.Msg)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
const handleSizeChange = (size) => {
|
|
|
searchForm.size = size;
|
|
|
getProductList();
|
|
@@ -164,7 +147,7 @@ const deleteProduct = (id) => {
|
|
|
type: 'warning',
|
|
|
}
|
|
|
).then(async () => {
|
|
|
- const res = await product.deleteProduct({id: id});
|
|
|
+ const res = await product.deleteProduct({ id: id });
|
|
|
if (res.data.code === 200) {
|
|
|
ElMessage.success("删除成功")
|
|
|
await getProductAll();
|