Przeglądaj źródła

走马灯调整

sunkean 3 lat temu
rodzic
commit
f7dc403165

+ 1 - 1
src/main/java/com/izouma/nineth/domain/MetaEmail.java

@@ -33,7 +33,7 @@ public class MetaEmail extends BaseEntity {
     @ExcelProperty("是否发布")
     private boolean publish;
 
-    @ApiModelProperty("是否发布")
+    @ApiModelProperty("是否已读")
     @Transient
     private boolean read;
 }

+ 12 - 6
src/main/java/com/izouma/nineth/web/MetaZouMaLightController.java

@@ -28,12 +28,6 @@ public class MetaZouMaLightController extends BaseController {
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
     public MetaZouMaLight save(@RequestBody MetaZouMaLight record) {
-        if (record.isPublish()) {
-            MetaZouMaLight metaZoumaLight = metaZouMaLightRepo.findByPublishAndDel(true, false);
-            if (Objects.nonNull(metaZoumaLight) && !Objects.equals(metaZoumaLight.getId(), record.getId())) {
-                throw new BusinessException("仅允许发布一条!");
-            }
-        }
         if (record.getId() != null) {
             MetaZouMaLight orig = metaZouMaLightRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
             ObjUtils.merge(orig, record);
@@ -65,6 +59,18 @@ public class MetaZouMaLightController extends BaseController {
         ExcelUtils.export(response, data);
     }
 
+    @PostMapping("/{id}/publish")
+    public void publish(@PathVariable Long id) {
+        MetaZouMaLight dbMetaZouMaLight = metaZouMaLightRepo.findByPublishAndDel(true, false);
+        if (Objects.nonNull(dbMetaZouMaLight)) {
+            dbMetaZouMaLight.setPublish(false);
+            metaZouMaLightRepo.save(dbMetaZouMaLight);
+        }
+        MetaZouMaLight metaZouMaLight = metaZouMaLightRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        metaZouMaLight.setPublish(true);
+        metaZouMaLightRepo.save(metaZouMaLight);
+    }
+
     @PostMapping("/metaQuery")
     public MetaRestResult<String> metaQuery() {
         return MetaRestResult.returnSuccess(metaZouMaLightRepo.findDescriptionByPublishAndDel(true, false));

+ 2 - 2
src/main/vue/src/views/MetaEmailList.vue

@@ -54,10 +54,10 @@
             </el-table-column>
 			<el-table-column label="操作" align="center" fixed="right" width="300">
 				<template slot-scope="{ row }">
+					<el-button @click="publish(row)" type="primary" size="mini" plain v-if="row && !row.publish"> 发布 </el-button>
 					<el-button @click="editRow(row)" type="primary" size="mini" plain v-if="row && !row.publish">
 						编辑
-					</el-button>
-					<el-button @click="publish(row)" type="primary" size="mini" plain v-if="row && !row.publish"> 发布 </el-button>
+					</el-button>					
 					<el-button @click="deleteRow(row)" type="danger" size="mini" plain v-if="row && !row.publish">
 						删除
 					</el-button>

+ 109 - 113
src/main/vue/src/views/MetaZouMaLightEdit.vue

@@ -1,121 +1,117 @@
 <template>
-	<div class="edit-view">
-		<page-title>
-			<el-button @click="$router.go(-1)" :disabled="saving"> 取消 </el-button>
-			<el-button @click="onDelete" :disabled="saving" type="danger" v-if="formData.id"> 删除 </el-button>
-			<el-button @click="onSave" :loading="saving" type="primary"> 保存 </el-button>
-		</page-title>
-		<div class="edit-view__content-wrapper">
-			<div class="edit-view__content-section">
-				<el-form
-					:model="formData"
-					:rules="rules"
-					ref="form"
-					label-width="94px"
-					label-position="right"
-					size="small"
-					style="max-width: 500px"
-				>
-					<el-form-item prop="description" label="走马灯详情" style="width: calc(100vw - 450px)">
-						<el-input
-							v-model="formData.description"
-							type="textarea"
-							:autosize="{ minRows: 3, maxRows: 20 }"
-							placeholder="请输入走马灯详情"
-						>
-						</el-input>
-					</el-form-item>
-					<el-form-item prop="publish" label="是否发布">
-						<el-switch v-model="formData.publish"> </el-switch>
-					</el-form-item>
-
-					<el-form-item class="form-submit">
-						<el-button @click="onSave" :loading="saving" type="primary"> 保存 </el-button>
-						<el-button @click="onDelete" :disabled="saving" type="danger" v-if="formData.id">
-							删除
-						</el-button>
-						<el-button @click="$router.go(-1)" :disabled="saving"> 取消 </el-button>
-					</el-form-item>
-				</el-form>
-			</div>
-		</div>
-	</div>
+    <div class="edit-view">
+        <page-title>
+            <el-button @click="$router.go(-1)" :disabled="saving"> 取消 </el-button>
+            <el-button @click="onDelete" :disabled="saving" type="danger" v-if="formData.id"> 删除 </el-button>
+            <el-button @click="onSave" :loading="saving" type="primary"> 保存 </el-button>
+        </page-title>
+        <div class="edit-view__content-wrapper">
+            <div class="edit-view__content-section">
+                <el-form
+                    :model="formData"
+                    :rules="rules"
+                    ref="form"
+                    label-width="94px"
+                    label-position="right"
+                    size="small"
+                    style="max-width: 500px"
+                >
+                    <el-form-item prop="description" label="走马灯详情" style="width: calc(100vw - 450px)">
+                        <el-input
+                            v-model="formData.description"
+                            type="textarea"
+                            :autosize="{ minRows: 3, maxRows: 20 }"
+                            placeholder="请输入走马灯详情"
+                        >
+                        </el-input>
+                    </el-form-item>
+                    <el-form-item class="form-submit">
+                        <el-button @click="onSave" :loading="saving" type="primary"> 保存 </el-button>
+                        <el-button @click="onDelete" :disabled="saving" type="danger" v-if="formData.id">
+                            删除
+                        </el-button>
+                        <el-button @click="$router.go(-1)" :disabled="saving"> 取消 </el-button>
+                    </el-form-item>
+                </el-form>
+            </div>
+        </div>
+    </div>
 </template>
 <script>
 export default {
-	name: 'MetaZouMaLightEdit',
-	created() {
-		if (this.$route.query.id) {
-			this.$http
-				.get('metaZouMaLight/get/' + this.$route.query.id)
-				.then(res => {
-					this.formData = res;
-				})
-				.catch(e => {
-					console.log(e);
-					this.$message.error(e.error);
-				});
-		}
-	},
-	data() {
-		return {
-			saving: false,
-			formData: {},
-			rules: {
-				description: [
-					{
-						required: true,
-						message: '请输入走马灯详情',
-						trigger: 'blur'
-					}
-				]
-			}
-		};
-	},
-	methods: {
-		onSave() {
-			this.$refs.form.validate(valid => {
-				if (valid) {
-					this.submit();
-				} else {
-					return false;
-				}
-			});
-		},
-		submit() {
-			let data = { ...this.formData };
+    name: 'MetaZouMaLightEdit',
+    created() {
+        if (this.$route.query.id) {
+            this.$http
+                .get('metaZouMaLight/get/' + this.$route.query.id)
+                .then(res => {
+                    this.formData = res;
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.$message.error(e.error);
+                });
+        }
+    },
+    data() {
+        return {
+            saving: false,
+            formData: {},
+            rules: {
+                description: [
+                    {
+                        required: true,
+                        message: '请输入走马灯详情',
+                        trigger: 'blur'
+                    }
+                ]
+            }
+        };
+    },
+    methods: {
+        onSave() {
+            this.$refs.form.validate(valid => {
+                if (valid) {
+                    this.submit();
+                } else {
+                    return false;
+                }
+            });
+        },
+        submit() {
+            let data = { ...this.formData };
 
-			this.saving = true;
-			this.$http
-				.post('/metaZouMaLight/save', data, { body: 'json' })
-				.then(res => {
-					this.saving = false;
-					this.$message.success('成功');
-					this.$router.go(-1);
-				})
-				.catch(e => {
-					console.log(e);
-					this.saving = false;
-					this.$message.error(e.error);
-				});
-		},
-		onDelete() {
-			this.$confirm('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
-				.then(() => {
-					return this.$http.post(`/metaZouMaLight/del/${this.formData.id}`);
-				})
-				.then(() => {
-					this.$message.success('删除成功');
-					this.$router.go(-1);
-				})
-				.catch(e => {
-					if (e !== 'cancel') {
-						console.log(e);
-						this.$message.error((e || {}).error || '删除失败');
-					}
-				});
-		}
-	}
+            this.saving = true;
+            this.$http
+                .post('/metaZouMaLight/save', data, { body: 'json' })
+                .then(res => {
+                    this.saving = false;
+                    this.$message.success('成功');
+                    this.$router.go(-1);
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.saving = false;
+                    this.$message.error(e.error);
+                });
+        },
+        onDelete() {
+            this.$confirm('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
+                .then(() => {
+                    return this.$http.post(`/metaZouMaLight/del/${this.formData.id}`);
+                })
+                .then(() => {
+                    this.$message.success('删除成功');
+                    this.$router.go(-1);
+                })
+                .catch(e => {
+                    if (e !== 'cancel') {
+                        console.log(e);
+                        this.$message.error((e || {}).error || '删除失败');
+                    }
+                });
+        }
+    }
 };
 </script>
 <style lang="less" scoped>

+ 178 - 166
src/main/vue/src/views/MetaZouMaLightList.vue

@@ -1,180 +1,192 @@
 <template>
-	<div class="list-view">
-		<page-title>
-			<el-button
-				@click="addRow"
-				type="primary"
-				icon="el-icon-plus"
-				:disabled="fetchingData || downloading"
-				class="filter-item"
-			>
-				新增
-			</el-button>
-			<el-button
-				@click="download"
-				icon="el-icon-upload2"
-				:loading="downloading"
-				:disabled="fetchingData"
-				class="filter-item"
-			>
-				导出
-			</el-button>
-		</page-title>
-		<div class="filters-container">
-			<el-input
-				placeholder="搜索..."
-				v-model="search"
-				clearable
-				class="filter-item search"
-				@keyup.enter.native="getData"
-			>
-				<el-button @click="getData" slot="append" icon="el-icon-search"> </el-button>
-			</el-input>
-		</div>
-		<el-table
-			:data="tableData"
-			row-key="id"
-			ref="table"
-			header-row-class-name="table-header-row"
-			header-cell-class-name="table-header-cell"
-			row-class-name="table-row"
-			cell-class-name="table-cell"
-			:height="tableHeight"
-			v-loading="fetchingData"
-		>
-			<el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
-			<el-table-column prop="id" label="ID" width="100"> </el-table-column>
-			<el-table-column prop="description" label="走马灯详情"> </el-table-column>
-            <el-table-column prop="publish" align="center" label="是否发布">
+    <div class="list-view">
+        <page-title>
+            <el-button
+                @click="addRow"
+                type="primary"
+                icon="el-icon-plus"
+                :disabled="fetchingData || downloading"
+                class="filter-item"
+            >
+                新增
+            </el-button>
+            <el-button
+                @click="download"
+                icon="el-icon-upload2"
+                :loading="downloading"
+                :disabled="fetchingData"
+                class="filter-item"
+            >
+                导出
+            </el-button>
+        </page-title>
+        <div class="filters-container">
+            <el-input
+                placeholder="搜索..."
+                v-model="search"
+                clearable
+                class="filter-item search"
+                @keyup.enter.native="getData"
+            >
+                <el-button @click="getData" slot="append" icon="el-icon-search"> </el-button>
+            </el-input>
+        </div>
+        <el-table
+            :data="tableData"
+            row-key="id"
+            ref="table"
+            header-row-class-name="table-header-row"
+            header-cell-class-name="table-header-cell"
+            row-class-name="table-row"
+            cell-class-name="table-cell"
+            :height="tableHeight"
+            v-loading="fetchingData"
+        >
+            <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
+            <el-table-column prop="id" align="center" label="ID" width="100"> </el-table-column>
+            <el-table-column prop="description" align="center" label="走马灯详情"> </el-table-column>
+            <el-table-column prop="publish" align="center" label="是否发布" width="100">
                 <template slot-scope="{ row }">
                     <el-tag :type="row.publish ? '' : 'info'"> {{ row.publish }} </el-tag>
                 </template>
             </el-table-column>
-			<el-table-column label="操作" align="center" fixed="right" width="150">
-				<template slot-scope="{ row }">
-					<el-button @click="editRow(row)" type="primary" size="mini" plain> 编辑 </el-button>
-					<el-button @click="deleteRow(row)" type="danger" size="mini" plain> 删除 </el-button>
-				</template>
-			</el-table-column>
-		</el-table>
-		<div class="pagination-wrapper">
-			<!-- <div class="multiple-mode-wrapper">
-                <el-button v-if="!multipleMode" @click="toggleMultipleMode(true)"> 批量编辑 </el-button>
-                <el-button-group v-else>
-                    <el-button @click="operation1"> 批量操作1 </el-button>
-                    <el-button @click="operation2"> 批量操作2 </el-button>
-                    <el-button @click="toggleMultipleMode(false)"> 取消 </el-button>
-                </el-button-group>
-            </div> -->
-			<el-pagination
-				background
-				@size-change="onSizeChange"
-				@current-change="onCurrentChange"
-				:current-page="page"
-				:page-sizes="[10, 20, 30, 40, 50]"
-				:page-size="pageSize"
-				layout="total, sizes, prev, pager, next, jumper"
-				:total="totalElements"
-			>
-			</el-pagination>
-		</div>
-	</div>
+            <el-table-column label="操作" align="center" fixed="right" width="300">
+                <template slot-scope="{ row }">
+                    <el-button @click="publish(row)" type="primary" size="mini" plain v-if="row && !row.publish">
+                        发布
+                    </el-button>
+                    <el-button @click="editRow(row)" type="primary" size="mini" plain> 编辑 </el-button>
+                    <el-button @click="deleteRow(row)" type="danger" size="mini" plain> 删除 </el-button>
+                </template>
+            </el-table-column>
+        </el-table>
+        <div class="pagination-wrapper">
+            <el-pagination
+                background
+                @size-change="onSizeChange"
+                @current-change="onCurrentChange"
+                :current-page="page"
+                :page-sizes="[10, 20, 30, 40, 50]"
+                :page-size="pageSize"
+                layout="total, sizes, prev, pager, next, jumper"
+                :total="totalElements"
+            >
+            </el-pagination>
+        </div>
+    </div>
 </template>
 <script>
 import { mapState } from 'vuex';
 import pageableTable from '@/mixins/pageableTable';
 
 export default {
-	name: 'MetaZouMaLightList',
-	mixins: [pageableTable],
-	data() {
-		return {
-			multipleMode: false,
-			search: '',
-			url: '/metaZouMaLight/all',
-			downloading: false
-		};
-	},
-	computed: {
-		selection() {
-			return this.$refs.table.selection.map(i => i.id);
-		}
-	},
-	methods: {
-		beforeGetData() {
-			return { search: this.search, query: { del: false } };
-		},
-		toggleMultipleMode(multipleMode) {
-			this.multipleMode = multipleMode;
-			if (!multipleMode) {
-				this.$refs.table.clearSelection();
-			}
-		},
-		addRow() {
-			this.$router.push({
-				path: '/metaZouMaLightEdit',
-				query: {
-					...this.$route.query
-				}
-			});
-		},
-		editRow(row) {
-			this.$router.push({
-				path: '/metaZouMaLightEdit',
-				query: {
-					id: row.id
-				}
-			});
-		},
-		download() {
-			this.downloading = true;
-			this.$axios
-				.get('/metaZouMaLight/excel', {
-					responseType: 'blob',
-					params: { size: 10000 }
-				})
-				.then(res => {
-					console.log(res);
-					this.downloading = false;
-					const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
-					const link = document.createElement('a');
-					link.href = downloadUrl;
-					link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
-					document.body.appendChild(link);
-					link.click();
-					link.remove();
-				})
-				.catch(e => {
-					console.log(e);
-					this.downloading = false;
-					this.$message.error(e.error);
-				});
-		},
-		operation1() {
-			this.$notify({
-				title: '提示',
-				message: this.selection
-			});
-		},
-		operation2() {
-			this.$message('操作2');
-		},
-		deleteRow(row) {
-			this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
-				.then(() => {
-					return this.$http.post(`/metaZouMaLight/del/${row.id}`);
-				})
-				.then(() => {
-					this.$message.success('删除成功');
-					this.getData();
-				})
-				.catch(e => {
-					if (e !== 'cancel') {
-						this.$message.error(e.error);
-					}
-				});
-		}
-	}
+    name: 'MetaZouMaLightList',
+    mixins: [pageableTable],
+    data() {
+        return {
+            multipleMode: false,
+            search: '',
+            url: '/metaZouMaLight/all',
+            downloading: false
+        };
+    },
+    computed: {
+        selection() {
+            return this.$refs.table.selection.map(i => i.id);
+        }
+    },
+    methods: {
+        beforeGetData() {
+            return { search: this.search, query: { del: false } };
+        },
+        toggleMultipleMode(multipleMode) {
+            this.multipleMode = multipleMode;
+            if (!multipleMode) {
+                this.$refs.table.clearSelection();
+            }
+        },
+        addRow() {
+            this.$router.push({
+                path: '/metaZouMaLightEdit',
+                query: {
+                    ...this.$route.query
+                }
+            });
+        },
+        editRow(row) {
+            this.$router.push({
+                path: '/metaZouMaLightEdit',
+                query: {
+                    id: row.id
+                }
+            });
+        },
+        download() {
+            this.downloading = true;
+            this.$axios
+                .get('/metaZouMaLight/excel', {
+                    responseType: 'blob',
+                    params: { size: 10000 }
+                })
+                .then(res => {
+                    console.log(res);
+                    this.downloading = false;
+                    const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
+                    const link = document.createElement('a');
+                    link.href = downloadUrl;
+                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    document.body.appendChild(link);
+                    link.click();
+                    link.remove();
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.downloading = false;
+                    this.$message.error(e.error);
+                });
+        },
+        operation1() {
+            this.$notify({
+                title: '提示',
+                message: this.selection
+            });
+        },
+        operation2() {
+            this.$message('操作2');
+        },
+        deleteRow(row) {
+            this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
+                .then(() => {
+                    return this.$http.post(`/metaZouMaLight/del/${row.id}`);
+                })
+                .then(() => {
+                    this.$message.success('删除成功');
+                    this.getData();
+                })
+                .catch(e => {
+                    if (e !== 'cancel') {
+                        this.$message.error(e.error);
+                    }
+                });
+        },
+        publish(row) {
+            this.$alert('请确定是否发布!如存在已发布走马灯信息,会将已发布走马灯状态改为未发布。', '提示', {
+                type: 'info'
+            })
+                .then(() => {
+                    return this.$http.post(`/metaZouMaLight/${row.id}/publish`);
+                })
+                .then(() => {
+                    this.$message.success('发布成功');
+                    this.getData();
+                })
+                .catch(e => {
+                    if (e !== 'cancel') {
+                        this.$message.error(e.error);
+                    }
+                });
+        }
+    }
 };
 </script>
 <style lang="less" scoped>