Browse Source

启动页管理

feature/yujt_analysis_pc
yujt 5 years ago
parent
commit
d02083bee9
  1. 196
      src/views/modules/api/startuppage-add-or-update.vue
  2. 85
      src/views/modules/api/startuppage.vue

196
src/views/modules/api/startuppage-add-or-update.vue

@ -0,0 +1,196 @@
<template>
<el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
<el-form-item prop="imgUrl"
v-loading="loading"
label="图片">
<el-upload class="avatar-uploader"
:action="uploadUrl"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:on-error="handelError"
:before-upload="beforeAvatarUpload">
<img v-if="dataForm.imgUrl"
:src="dataForm.imgUrl"
class="avatar">
<i v-else
class="el-icon-plus avatar-uploader-icon"></i>
<div slot="tip"
class="el-upload__tip">只能上传jpg/png文件且不超过500kb</div>
</el-upload>
</el-form-item>
<el-form-item label="停留时长" prop="duration">
<el-input-number v-model="dataForm.duration" :min="1" ></el-input-number>
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input-number v-model="dataForm.sort" :min="0" ></el-input-number>
</el-form-item>
<el-form-item label="是否启用" prop="enableFlag">
<el-select v-model="dataForm.enableFlag" placeholder="是否启用" clearable>
<el-option v-for="item in enableFlagArr"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input type="textarea"
:rows="3"
v-model="dataForm.remark" placeholder="备注"
maxlength="2000"></el-input>
</el-form-item>
</el-form>
<template slot="footer">
<el-button @click="visible = false">{{ $t('cancel') }}</el-button>
<el-button type="primary" @click="dataFormSubmitHandle()" :disabled="btnAble">{{ $t('confirm') }}</el-button>
</template>
</el-dialog>
</template>
<script>
import Cookies from 'js-cookie'
import debounce from 'lodash/debounce'
export default {
data () {
return {
visible: false,
dataForm: {
id: '',
imgUrl: '',
duration: '',
enableFlag: '',
remark: '',
revision: '',
createdBy: '',
createdTime: '',
updatedBy: '',
updatedTime: '',
delFlag: ''
},
uploadUrl: '',
loading: false,
enableFlagArr: [
{
label: '是',
value: '1'
},
{
label: '否',
value: '0'
}
],
btnAble: false
}
},
computed: {
dataRule () {
return {
imgUrl: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
duration: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
enableFlag: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
sort: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
]
}
}
},
created () {
this.uploadUrl = `${window.SITE_CONFIG['apiURL']}/oss/file/upload?token=${Cookies.get('token')}`
this.dataForm.imgUrl = ''
},
methods: {
handleAvatarSuccess (res, file) {
this.loading = false
this.dataForm.imgUrl = res.data.url
this.btnAble = false
},
beforeAvatarUpload (file) {
this.loading = true
this.btnAble = true
},
handelError () {
this.loading = false
},
init () {
this.dataForm.imgUrl = ''
this.btnAble = false
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.id) {
this.getInfo()
}
})
},
//
getInfo () {
this.$http.get(`/api/startuppage/${this.dataForm.id}`).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.dataForm = {
...this.dataForm,
...res.data
}
}).catch(() => {})
},
//
dataFormSubmitHandle: debounce(function () {
this.$refs['dataForm'].validate((valid) => {
if (!valid) {
return false
}
this.btnAble = true
this.$http[!this.dataForm.id ? 'post' : 'put']('/api/startuppage/', this.dataForm).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.btnAble = false
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
}).catch(() => {})
})
}, 1000, { 'leading': true, 'trailing': false })
}
}
</script>
<style>
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409eff;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
}
</style>

85
src/views/modules/api/startuppage.vue

@ -0,0 +1,85 @@
<template>
<el-card shadow="never" class="aui-card--fill">
<div class="mod-__startuppage}">
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item>
<el-button v-if="$hasPermission('api:startuppage:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
</el-form-item>
</el-form>
<el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
<el-table-column label="序号" header-align="center" align="center" width="50px">
<template slot-scope="scope">
{{scope.$index+1}}
</template>
</el-table-column>
<el-table-column prop="imgUrl" label="图片" header-align="center" align="center">
<template slot-scope="scope">
<el-image
style="width: 100px; height: 100px"
:src="scope.row.imgUrl"
:preview-src-list="scope.row.imgUrlList">
</el-image>
</template>
</el-table-column>
<el-table-column prop="duration" label="停留时长(秒)" header-align="center" align="center"></el-table-column>
<el-table-column prop="enableFlag" label="是否启用" header-align="center" align="center" :formatter="enableFlagFormat"></el-table-column>
<el-table-column prop="sort" label="排序" header-align="center" align="center" ></el-table-column>
<el-table-column prop="remark" label="备注" header-align="center" align="center" :show-overflow-tooltip='true'></el-table-column>
<el-table-column prop="createdTime" label="创建时间" header-align="center" align="center"></el-table-column>
<el-table-column prop="updatedTime" label="更新时间" header-align="center" align="center"></el-table-column>
<el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
<template slot-scope="scope">
<el-button v-if="$hasPermission('api:startuppage:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
:current-page="page"
:page-sizes="[10, 20, 50, 100]"
:page-size="limit"
:total="total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="pageSizeChangeHandle"
@current-change="pageCurrentChangeHandle">
</el-pagination>
<!-- 弹窗, 新增 / 修改 -->
<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
</div>
</el-card>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './startuppage-add-or-update'
import 'element-ui/lib/theme-chalk/image.css'
export default {
mixins: [mixinViewModule],
data () {
return {
mixinViewModuleOptions: {
getDataListURL: '/api/startuppage/page',
getDataListIsPage: true,
deleteURL: '/api/startuppage',
deleteIsBatch: true
},
dataForm: {
id: ''
},
previewImgList: []
}
},
components: {
AddOrUpdate
},
methods: {
enableFlagFormat: function (row, column) {
let enableFlag = row.enableFlag
if (enableFlag === '0') {
return '否'
} else if (enableFlag === '1') {
return '是'
}
}
}
}
</script>
Loading…
Cancel
Save