2024-08-19 13:29:02 +08:00

302 lines
9.5 KiB
Vue

<template>
<div class="app-container">
<!--div class="filter-container">
<el-button v-show="visibleAddannouncement" class="filter-item" style="margin-left: 10px;" type="primary" @click="handleCreate">
新增公告
</el-button>
</div-->
<el-table
:data="anncList"
border
fit
highlight-current-row
style="width: 100%;"
>
<!-- <el-table-column-->
<!-- fixed-->
<!-- prop="date"-->
<!-- label="日期"-->
<!-- >-->
<!-- </el-table-column>-->
<el-table-column
prop="annc_type"
label="公告类型"
width="150"
align="center"
>
<template slot-scope="scope">
<el-tag v-if="scope.row.annc_type === 1" effect="plain" type="">最低版本支持公告</el-tag>
<el-tag v-if="scope.row.annc_type === 2" effect="plain" type="">白名单版本公告</el-tag>
<el-tag v-if="scope.row.annc_type === 3" effect="plain" type="">当前版本公告</el-tag>
</template>
</el-table-column>
<el-table-column
prop="title"
label="标题"
width="100"
/>
<el-table-column
prop="version"
label="版本"
width="60"
>
<template slot-scope="scope">
<span v-if="scope.row.annc_type===3">当前版本</span>
<span v-else>{{ scope.row.version }}</span>
</template>
</el-table-column>
<el-table-column
label="平台"
width="80"
align="center"
>
<template slot-scope="scope">
<svg-icon v-if="scope.row.platform === 1" style="font-size: 20px;color: #4A9FF9" icon-class="Android" />
<svg-icon v-if="scope.row.platform === 2" style="font-size: 20px;color: #333333" icon-class="IOS" />
</template>
</el-table-column>
<el-table-column
label="类型"
width="120"
align="center"
>
<template slot-scope="scope">
<el-tag v-if="scope.row.click_type === 0" effect="plain" type="warning">不能进游戏</el-tag>
<el-tag v-if="scope.row.click_type === 1" effect="plain" type="">可以进游戏</el-tag>
</template>
</el-table-column>
<el-table-column
label="是否生效"
width="80"
align="center"
>
<template slot-scope="scope">
<svg-icon v-if="scope.row.enable === 1" icon-class="ok" style="font-size: 20px;" />
<svg-icon v-else icon-class="no" style="font-size: 20px;" />
</template>
</el-table-column>
<!-- <el-table-column
prop="desc"
label="描述"
width="195"
/> -->
<el-table-column
label="公告内容"
prop="content"
:show-overflow-tooltip="true"
/>
<el-table-column
fixed="right"
label="操作"
width="100"
>
<template slot-scope="scope">
<el-button v-show="visibleEditannouncement" type="text" size="small" @click="handleUpdate(scope.row)">编辑</el-button>
</template>
</el-table-column>
</el-table>
<!-- <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />-->
<el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible">
<el-form ref="form" :rules="rules" :model="form" label-position="left" label-width="80px" style="width: 400px; margin-left:50px;">
<el-form-item label="公告标题" prop="title">
<el-input v-model="form.title" />
</el-form-item>
<el-form-item label="Version" prop="version">
<el-input v-model="versiontxt" :readonly="versionreadonly" />
</el-form-item>
<el-form-item label="型号" prop="platform">
<el-radio-group v-model="form.platform" disabled>
<el-radio :label="1">Android</el-radio>
<el-radio :label="2">IOS</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="类型" prop="click_type">
<el-radio-group v-model="form.click_type">
<el-radio :label="0">不能进游戏</el-radio>
<el-radio :label="1">可以进游戏</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="是否生效">
<el-switch
v-model="form.enable"
:active-value="1"
:inactive-value="0"
active-color="#13ce66"
inactive-color="#ff4949"
/>
</el-form-item>
<!-- <el-form-item label="公告时间">-->
<!-- <el-col :span="11">-->
<!-- <el-date-picker v-model="from.time1" type="date" placeholder="选择日期" style="width: 100%;"></el-date-picker>-->
<!-- </el-col>-->
<!-- <el-col class="line" :span="2">-</el-col>-->
<!-- <el-col :span="11">-->
<!-- <el-time-picker v-model="from.time2" placeholder="选择时间" style="width: 100%;"></el-time-picker>-->
<!-- </el-col>-->
<!-- </el-form-item>-->
<el-form-item label="公告内容" prop="content">
<el-input v-model="form.content" type="textarea" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">
Cancel
</el-button>
<el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
Confirm
</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
// import Pagination from '@/components/Pagination/index.vue'
import { addAnnc, getAnncList, updateAnnc } from '@/api/announcement'
import { Message } from 'element-ui'
import { checkuipermission } from '@/store/modules/permission'
export default {
components: {
},
data() {
return {
form: {
annc_type: '',
title: '',
click_type: '',
content: '',
version: '',
platform: '',
enable: 1
},
versiontxt: '当前版本',
versionreadonly: false,
dialogFormVisible: false,
dialogStatus: '',
dialogTitle: '发布公告',
listLoading: true,
anncList: [],
visibleAddannouncement: false,
visibleEditannouncement: false,
rules: {
title: [{ required: true, message: 'title is required', trigger: 'blur' }],
version: [{ required: true, message: 'version is required', trigger: 'blur' }],
platform: [{ required: true, message: '请选择型号', trigger: 'blur' }],
click_type: [{ required: true, message: '是否可进游戏', trigger: 'blur' }],
content: [{ required: true, message: '请输入公告内容', trigger: 'blur' }]
}
}
},
created() {
this.getList()
if (checkuipermission('addannouncement')) {
this.visibleAddannouncement = true
} else {
this.visibleAddannouncement = false
}
if (checkuipermission('editannouncement')) {
this.visibleEditannouncement = true
} else {
this.visibleEditannouncement = false
}
},
methods: {
handleUpdate(row) {
console.log(row)
this.form.annc_type = row.annc_type
this.form.title = row.title
this.form.version = row.version
this.form.platform = row.platform
this.form.click_type = row.click_type
this.form.content = row.content
this.form.enable = row.enable
this.form.idx = row.idx
if (this.form.annc_type !== 3) {
this.versiontxt = this.form.version
this.versionreadonly = false
} else {
this.versiontxt = '当前版本'
this.versionreadonly = true
}
this.dialogStatus = 'update'
this.dialogTitle = '修改公告'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['form'].clearValidate()
})
},
getList() {
getAnncList().then(response => {
if (response.code === 0) {
this.anncList = response.data
}
})
},
handleCreate() {
this.resetTemp()
this.dialogStatus = 'create'
this.dialogTitle = '发布公告'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['form'].clearValidate()
})
},
resetTemp() {
this.form = {
annc_type: '',
title: '',
click_type: '',
content: '',
version: '',
platform: '',
enable: 1
}
},
createData() {
this.$refs['form'].validate((valid) => {
if (valid) {
addAnnc(this.form).then(response => {
if (response.code === 0) {
this.dialogFormVisible = false
this.getList()
Message({
message: 'Created Successfully',
type: 'success',
duration: 2 * 1000
})
}
})
}
})
},
updateData() {
if (this.form.annc_type !== 3) {
this.form.version = this.versiontxt
}
this.$refs['form'].validate((valid) => {
if (valid) {
updateAnnc(this.form).then(response => {
if (response.code === 0) {
this.dialogFormVisible = false
this.getList()
this.$notify({
title: 'Success',
message: 'Updated Successfully',
type: 'success',
duration: 2000
})
}
})
}
})
}
}
}
</script>