轮播图装修问题修复
This commit is contained in:
parent
9ee8de8321
commit
4747e467e8
|
|
@ -1,34 +1,33 @@
|
||||||
import request from "@/utils/request";
|
import request from '@/utils/request'
|
||||||
|
|
||||||
// 新增上传首页轮播图
|
// 新增上传首页轮播图
|
||||||
export const addHomeSwiperApi = (data) => {
|
export const addHomeSwiperApi = (data) => {
|
||||||
return request({
|
return request({
|
||||||
url: "/material-mall/bm_slide_show",
|
url: '/material-mall/bm_slide_show',
|
||||||
method: "post",
|
method: 'post',
|
||||||
data,
|
data,
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
// 轮播图列表
|
// 轮播图列表
|
||||||
export const getSwiperListApi = (data) => {
|
export const getSwiperListApi = (data) => {
|
||||||
return request({
|
return request({
|
||||||
url: "/material-mall/bm_slide_show/list",
|
url: '/material-mall/bm_slide_show/list',
|
||||||
method: "get",
|
method: 'get',
|
||||||
params: data,
|
params: data,
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
// 修改轮播图状态
|
// 修改轮播图状态
|
||||||
export const editHomeSwiperTypeApi = (data) => {
|
export const editHomeSwiperTypeApi = (data) => {
|
||||||
return request({
|
return request({
|
||||||
url: "/material-mall/bm_slide_show/edit",
|
url: '/material-mall/bm_slide_show/edit',
|
||||||
method: "post",
|
method: 'post',
|
||||||
data,
|
data,
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
// 删除轮播图
|
// 删除轮播图
|
||||||
export const deleteHomeSwiperApi = (id) => {
|
export const deleteHomeSwiperApi = (id) => {
|
||||||
return request({
|
return request({
|
||||||
url: `/material-mall/bm_slide_show/del/${id}`,
|
url: `/material-mall/bm_slide_show/del/${id}`,
|
||||||
method: "post",
|
method: 'post',
|
||||||
data,
|
})
|
||||||
});
|
}
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,19 @@
|
||||||
<template>
|
<template>
|
||||||
<el-color-picker
|
<el-color-picker
|
||||||
v-model="theme"
|
v-model="theme"
|
||||||
:predefine="['#409EFF', '#1890ff', '#304156','#212121','#11a983', '#13c2c2', '#6959CD', '#f5222d', ]"
|
:predefine="[
|
||||||
class="theme-picker"
|
'#409EFF',
|
||||||
popper-class="theme-picker-dropdown"
|
'#1890ff',
|
||||||
/>
|
'#304156',
|
||||||
|
'#212121',
|
||||||
|
'#11a983',
|
||||||
|
'#13c2c2',
|
||||||
|
'#6959CD',
|
||||||
|
'#f5222d',
|
||||||
|
]"
|
||||||
|
class="theme-picker"
|
||||||
|
popper-class="theme-picker-dropdown"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -12,162 +21,185 @@ const version = require('element-ui/package.json').version // element-ui version
|
||||||
const ORIGINAL_THEME = '#409EFF' // default color
|
const ORIGINAL_THEME = '#409EFF' // default color
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
chalk: '', // content of theme-chalk css
|
chalk: '', // content of theme-chalk css
|
||||||
theme: ''
|
theme: '',
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
defaultTheme() {
|
|
||||||
return this.$store.state.settings.theme
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
defaultTheme: {
|
|
||||||
handler: function(val, oldVal) {
|
|
||||||
this.theme = val
|
|
||||||
},
|
|
||||||
immediate: true
|
|
||||||
},
|
|
||||||
async theme(val) {
|
|
||||||
await this.setTheme(val)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
if(this.defaultTheme !== ORIGINAL_THEME) {
|
|
||||||
this.setTheme(this.defaultTheme)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
async setTheme(val) {
|
|
||||||
const oldVal = this.chalk ? this.theme : ORIGINAL_THEME
|
|
||||||
if (typeof val !== 'string') return
|
|
||||||
const themeCluster = this.getThemeCluster(val.replace('#', ''))
|
|
||||||
const originalCluster = this.getThemeCluster(oldVal.replace('#', ''))
|
|
||||||
|
|
||||||
const getHandler = (variable, id) => {
|
|
||||||
return () => {
|
|
||||||
const originalCluster = this.getThemeCluster(ORIGINAL_THEME.replace('#', ''))
|
|
||||||
const newStyle = this.updateStyle(this[variable], originalCluster, themeCluster)
|
|
||||||
|
|
||||||
let styleTag = document.getElementById(id)
|
|
||||||
if (!styleTag) {
|
|
||||||
styleTag = document.createElement('style')
|
|
||||||
styleTag.setAttribute('id', id)
|
|
||||||
document.head.appendChild(styleTag)
|
|
||||||
}
|
|
||||||
styleTag.innerText = newStyle
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.chalk) {
|
|
||||||
const url = `https://unpkg.com/element-ui@${version}/lib/theme-chalk/index.css`
|
|
||||||
await this.getCSSString(url, 'chalk')
|
|
||||||
}
|
|
||||||
|
|
||||||
const chalkHandler = getHandler('chalk', 'chalk-style')
|
|
||||||
|
|
||||||
chalkHandler()
|
|
||||||
|
|
||||||
const styles = [].slice.call(document.querySelectorAll('style'))
|
|
||||||
.filter(style => {
|
|
||||||
const text = style.innerText
|
|
||||||
return new RegExp(oldVal, 'i').test(text) && !/Chalk Variables/.test(text)
|
|
||||||
})
|
|
||||||
styles.forEach(style => {
|
|
||||||
const { innerText } = style
|
|
||||||
if (typeof innerText !== 'string') return
|
|
||||||
style.innerText = this.updateStyle(innerText, originalCluster, themeCluster)
|
|
||||||
})
|
|
||||||
|
|
||||||
this.$emit('change', val)
|
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
updateStyle(style, oldCluster, newCluster) {
|
defaultTheme() {
|
||||||
let newStyle = style
|
return this.$store.state.settings.theme
|
||||||
oldCluster.forEach((color, index) => {
|
},
|
||||||
newStyle = newStyle.replace(new RegExp(color, 'ig'), newCluster[index])
|
|
||||||
})
|
|
||||||
return newStyle
|
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
getCSSString(url, variable) {
|
defaultTheme: {
|
||||||
return new Promise(resolve => {
|
handler: function (val, oldVal) {
|
||||||
const xhr = new XMLHttpRequest()
|
this.theme = val
|
||||||
xhr.onreadystatechange = () => {
|
},
|
||||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
immediate: true,
|
||||||
this[variable] = xhr.responseText.replace(/@font-face{[^}]+}/, '')
|
},
|
||||||
resolve()
|
async theme(val) {
|
||||||
}
|
await this.setTheme(val)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
if (this.defaultTheme !== ORIGINAL_THEME) {
|
||||||
|
this.setTheme(this.defaultTheme)
|
||||||
}
|
}
|
||||||
xhr.open('GET', url)
|
|
||||||
xhr.send()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getThemeCluster(theme) {
|
methods: {
|
||||||
const tintColor = (color, tint) => {
|
async setTheme(val) {
|
||||||
let red = parseInt(color.slice(0, 2), 16)
|
const oldVal = this.chalk ? this.theme : ORIGINAL_THEME
|
||||||
let green = parseInt(color.slice(2, 4), 16)
|
if (typeof val !== 'string') return
|
||||||
let blue = parseInt(color.slice(4, 6), 16)
|
const themeCluster = this.getThemeCluster(val.replace('#', ''))
|
||||||
|
const originalCluster = this.getThemeCluster(
|
||||||
|
oldVal.replace('#', ''),
|
||||||
|
)
|
||||||
|
|
||||||
if (tint === 0) { // when primary color is in its rgb space
|
const getHandler = (variable, id) => {
|
||||||
return [red, green, blue].join(',')
|
return () => {
|
||||||
} else {
|
const originalCluster = this.getThemeCluster(
|
||||||
red += Math.round(tint * (255 - red))
|
ORIGINAL_THEME.replace('#', ''),
|
||||||
green += Math.round(tint * (255 - green))
|
)
|
||||||
blue += Math.round(tint * (255 - blue))
|
const newStyle = this.updateStyle(
|
||||||
|
this[variable],
|
||||||
|
originalCluster,
|
||||||
|
themeCluster,
|
||||||
|
)
|
||||||
|
|
||||||
red = red.toString(16)
|
let styleTag = document.getElementById(id)
|
||||||
green = green.toString(16)
|
if (!styleTag) {
|
||||||
blue = blue.toString(16)
|
styleTag = document.createElement('style')
|
||||||
|
styleTag.setAttribute('id', id)
|
||||||
|
document.head.appendChild(styleTag)
|
||||||
|
}
|
||||||
|
styleTag.innerText = newStyle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return `#${red}${green}${blue}`
|
if (!this.chalk) {
|
||||||
}
|
const url = `https://unpkg.com/element-ui@${version}/lib/theme-chalk/index.css`
|
||||||
}
|
await this.getCSSString(url, 'chalk')
|
||||||
|
}
|
||||||
|
|
||||||
const shadeColor = (color, shade) => {
|
const chalkHandler = getHandler('chalk', 'chalk-style')
|
||||||
let red = parseInt(color.slice(0, 2), 16)
|
|
||||||
let green = parseInt(color.slice(2, 4), 16)
|
|
||||||
let blue = parseInt(color.slice(4, 6), 16)
|
|
||||||
|
|
||||||
red = Math.round((1 - shade) * red)
|
chalkHandler()
|
||||||
green = Math.round((1 - shade) * green)
|
|
||||||
blue = Math.round((1 - shade) * blue)
|
|
||||||
|
|
||||||
red = red.toString(16)
|
const styles = [].slice
|
||||||
green = green.toString(16)
|
.call(document.querySelectorAll('style'))
|
||||||
blue = blue.toString(16)
|
.filter((style) => {
|
||||||
|
const text = style.innerText
|
||||||
|
return (
|
||||||
|
new RegExp(oldVal, 'i').test(text) &&
|
||||||
|
!/Chalk Variables/.test(text)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
styles.forEach((style) => {
|
||||||
|
const { innerText } = style
|
||||||
|
if (typeof innerText !== 'string') return
|
||||||
|
style.innerText = this.updateStyle(
|
||||||
|
innerText,
|
||||||
|
originalCluster,
|
||||||
|
themeCluster,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
return `#${red}${green}${blue}`
|
this.$emit('change', val)
|
||||||
}
|
},
|
||||||
|
|
||||||
const clusters = [theme]
|
updateStyle(style, oldCluster, newCluster) {
|
||||||
for (let i = 0; i <= 9; i++) {
|
let newStyle = style
|
||||||
clusters.push(tintColor(theme, Number((i / 10).toFixed(2))))
|
oldCluster.forEach((color, index) => {
|
||||||
}
|
newStyle = newStyle.replace(
|
||||||
clusters.push(shadeColor(theme, 0.1))
|
new RegExp(color, 'ig'),
|
||||||
return clusters
|
newCluster[index],
|
||||||
}
|
)
|
||||||
}
|
})
|
||||||
|
return newStyle
|
||||||
|
},
|
||||||
|
|
||||||
|
getCSSString(url, variable) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const xhr = new XMLHttpRequest()
|
||||||
|
xhr.onreadystatechange = () => {
|
||||||
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
|
this[variable] = xhr.responseText.replace(
|
||||||
|
/@font-face{[^}]+}/,
|
||||||
|
'',
|
||||||
|
)
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhr.open('GET', url)
|
||||||
|
xhr.send()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
getThemeCluster(theme) {
|
||||||
|
const tintColor = (color, tint) => {
|
||||||
|
let red = parseInt(color.slice(0, 2), 16)
|
||||||
|
let green = parseInt(color.slice(2, 4), 16)
|
||||||
|
let blue = parseInt(color.slice(4, 6), 16)
|
||||||
|
|
||||||
|
if (tint === 0) {
|
||||||
|
// when primary color is in its rgb space
|
||||||
|
return [red, green, blue].join(',')
|
||||||
|
} else {
|
||||||
|
red += Math.round(tint * (255 - red))
|
||||||
|
green += Math.round(tint * (255 - green))
|
||||||
|
blue += Math.round(tint * (255 - blue))
|
||||||
|
|
||||||
|
red = red.toString(16)
|
||||||
|
green = green.toString(16)
|
||||||
|
blue = blue.toString(16)
|
||||||
|
|
||||||
|
return `#${red}${green}${blue}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const shadeColor = (color, shade) => {
|
||||||
|
let red = parseInt(color.slice(0, 2), 16)
|
||||||
|
let green = parseInt(color.slice(2, 4), 16)
|
||||||
|
let blue = parseInt(color.slice(4, 6), 16)
|
||||||
|
|
||||||
|
red = Math.round((1 - shade) * red)
|
||||||
|
green = Math.round((1 - shade) * green)
|
||||||
|
blue = Math.round((1 - shade) * blue)
|
||||||
|
|
||||||
|
red = red.toString(16)
|
||||||
|
green = green.toString(16)
|
||||||
|
blue = blue.toString(16)
|
||||||
|
|
||||||
|
return `#${red}${green}${blue}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const clusters = [theme]
|
||||||
|
for (let i = 0; i <= 9; i++) {
|
||||||
|
clusters.push(tintColor(theme, Number((i / 10).toFixed(2))))
|
||||||
|
}
|
||||||
|
clusters.push(shadeColor(theme, 0.1))
|
||||||
|
return clusters
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.theme-message,
|
.theme-message,
|
||||||
.theme-picker-dropdown {
|
.theme-picker-dropdown {
|
||||||
z-index: 99999 !important;
|
z-index: 99999 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.theme-picker .el-color-picker__trigger {
|
.theme-picker .el-color-picker__trigger {
|
||||||
height: 26px !important;
|
height: 26px !important;
|
||||||
width: 26px !important;
|
width: 26px !important;
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.theme-picker-dropdown .el-color-dropdown__link-btn {
|
.theme-picker-dropdown .el-color-dropdown__link-btn {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,280 +1,279 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<el-row :gutter="10" class="mb8">
|
<el-row :gutter="10" class="mb8">
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
plain
|
plain
|
||||||
icon="el-icon-plus"
|
icon="el-icon-plus"
|
||||||
size="mini"
|
size="mini"
|
||||||
@click="handleAdd"
|
@click="handleAdd"
|
||||||
>
|
>
|
||||||
新增轮播图
|
新增轮播图
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<el-table :data="swiperList" border>
|
|
||||||
<el-table-column label="序号" align="center" width="100" type="index" />
|
|
||||||
<el-table-column
|
|
||||||
prop="slidePicture"
|
|
||||||
label="图片链接"
|
|
||||||
align="center"
|
|
||||||
show-overflow-tooltip
|
|
||||||
/>
|
|
||||||
<el-table-column prop="isShow" label="是否禁用" align="center">
|
|
||||||
<template slot-scope="{ row }">
|
|
||||||
<el-switch
|
|
||||||
active-text="激活"
|
|
||||||
inactive-text="禁用"
|
|
||||||
v-model="row.delFlag"
|
|
||||||
@change="onSwitchChange($event, row)"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
prop="slideLink"
|
|
||||||
label="外部链接"
|
|
||||||
align="center"
|
|
||||||
show-overflow-tooltip
|
|
||||||
/>
|
|
||||||
<el-table-column label="操作" align="center">
|
|
||||||
<template slot-scope="{ row }">
|
|
||||||
<el-button size="mini" type="danger" @click="onClickDelete(row)">
|
|
||||||
删除
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
|
|
||||||
<el-dialog
|
|
||||||
width="50%"
|
|
||||||
append-to-body
|
|
||||||
title="新增轮播图"
|
|
||||||
:visible.sync="addSwiperVisible"
|
|
||||||
>
|
|
||||||
<el-form
|
|
||||||
ref="addSwiperFormRef"
|
|
||||||
:model="addSwiperForm"
|
|
||||||
:rules="addSwiperFormRules"
|
|
||||||
label-width="120px"
|
|
||||||
>
|
|
||||||
<el-row>
|
|
||||||
<el-col :span="24">
|
|
||||||
<el-form-item label="外部链接:" prop="slideLink">
|
|
||||||
<el-input
|
|
||||||
placeholder="请输入外部链接"
|
|
||||||
v-model="addSwiperForm.slideLink"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="24">
|
|
||||||
<el-form-item label="是否激活:" prop="delFlag">
|
|
||||||
<el-switch
|
|
||||||
active-text="激活"
|
|
||||||
inactive-text="禁用"
|
|
||||||
v-model="addSwiperForm.delFlag"
|
|
||||||
></el-switch>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="24">
|
|
||||||
<el-form-item label="轮播图上传:" prop="fileList">
|
|
||||||
<el-upload
|
|
||||||
:limit="1"
|
|
||||||
:headers="headers"
|
|
||||||
:show-file-list="true"
|
|
||||||
:action="uploadFileUrl"
|
|
||||||
list-type="picture-card"
|
|
||||||
:on-exceed="handleExceed"
|
|
||||||
:on-remove="handleRemove"
|
|
||||||
:on-preview="handlePreview"
|
|
||||||
:on-success="handleSuccess"
|
|
||||||
:before-upload="handleBeforeUpload"
|
|
||||||
:file-list="addSwiperForm.fileList"
|
|
||||||
>
|
|
||||||
<i class="el-icon-plus"></i>
|
|
||||||
</el-upload>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-form>
|
|
||||||
<div slot="footer" class="dialog-footer">
|
|
||||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
||||||
<el-button @click="cancel">取 消</el-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<el-dialog
|
<el-table :data="swiperList" border>
|
||||||
width="30%"
|
<el-table-column
|
||||||
append-to-body
|
label="序号"
|
||||||
:before-close="
|
align="center"
|
||||||
() => {
|
width="100"
|
||||||
dialogInnerVisible = false;
|
type="index"
|
||||||
}
|
/>
|
||||||
"
|
<el-table-column
|
||||||
:visible.sync="dialogInnerVisible"
|
prop="slidePicture"
|
||||||
>
|
label="图片链接"
|
||||||
<img
|
align="center"
|
||||||
:src="previewUrl"
|
show-overflow-tooltip
|
||||||
style="display: block; max-width: 100%; margin: 0 auto"
|
/>
|
||||||
/>
|
<el-table-column prop="isShow" label="是否禁用" align="center">
|
||||||
</el-dialog>
|
<template slot-scope="{ row }">
|
||||||
</el-dialog>
|
<el-switch
|
||||||
</div>
|
active-text="激活"
|
||||||
|
inactive-text="禁用"
|
||||||
|
v-model="row.delFlag"
|
||||||
|
@change="onSwitchChange($event, row)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column
|
||||||
|
prop="slideLink"
|
||||||
|
label="外部链接"
|
||||||
|
align="center"
|
||||||
|
show-overflow-tooltip
|
||||||
|
/>
|
||||||
|
<el-table-column label="操作" align="center">
|
||||||
|
<template slot-scope="{ row }">
|
||||||
|
<el-button
|
||||||
|
size="mini"
|
||||||
|
type="danger"
|
||||||
|
@click="onClickDelete(row)"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<el-dialog
|
||||||
|
width="50%"
|
||||||
|
append-to-body
|
||||||
|
title="新增轮播图"
|
||||||
|
:visible.sync="addSwiperVisible"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
ref="addSwiperFormRef"
|
||||||
|
:model="addSwiperForm"
|
||||||
|
:rules="addSwiperFormRules"
|
||||||
|
label-width="120px"
|
||||||
|
>
|
||||||
|
<el-row>
|
||||||
|
<el-col :span="24">
|
||||||
|
<el-form-item label="外部链接:" prop="slideLink">
|
||||||
|
<el-input
|
||||||
|
placeholder="请输入外部链接"
|
||||||
|
v-model="addSwiperForm.slideLink"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="24">
|
||||||
|
<el-form-item label="是否激活:" prop="delFlag">
|
||||||
|
<el-switch
|
||||||
|
active-text="激活"
|
||||||
|
inactive-text="禁用"
|
||||||
|
v-model="addSwiperForm.delFlag"
|
||||||
|
></el-switch>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="24">
|
||||||
|
<el-form-item label="轮播图上传:" prop="fileList">
|
||||||
|
<el-upload
|
||||||
|
:limit="1"
|
||||||
|
:headers="headers"
|
||||||
|
:show-file-list="true"
|
||||||
|
:action="uploadFileUrl"
|
||||||
|
list-type="picture-card"
|
||||||
|
:on-exceed="handleExceed"
|
||||||
|
:on-remove="handleRemove"
|
||||||
|
:on-preview="handlePreview"
|
||||||
|
:on-success="handleSuccess"
|
||||||
|
:before-upload="handleBeforeUpload"
|
||||||
|
:file-list="addSwiperForm.fileList"
|
||||||
|
>
|
||||||
|
<i class="el-icon-plus"></i>
|
||||||
|
</el-upload>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</el-form>
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
<el-button @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-dialog
|
||||||
|
width="30%"
|
||||||
|
append-to-body
|
||||||
|
:before-close="
|
||||||
|
() => {
|
||||||
|
dialogInnerVisible = false
|
||||||
|
}
|
||||||
|
"
|
||||||
|
:visible.sync="dialogInnerVisible"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
:src="previewUrl"
|
||||||
|
style="display: block; max-width: 100%; margin: 0 auto"
|
||||||
|
/>
|
||||||
|
</el-dialog>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getToken } from "@/utils/auth";
|
import { getToken } from '@/utils/auth'
|
||||||
import {
|
import {
|
||||||
addHomeSwiperApi,
|
addHomeSwiperApi,
|
||||||
getSwiperListApi,
|
getSwiperListApi,
|
||||||
deleteHomeSwiperApi,
|
deleteHomeSwiperApi,
|
||||||
editHomeSwiperTypeApi,
|
editHomeSwiperTypeApi,
|
||||||
} from "@/api/swiper-manage/index.js";
|
} from '@/api/swiper-manage/index.js'
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
uploadFileUrl: process.env.VUE_APP_BASE_API + "/file/upload",
|
uploadFileUrl: process.env.VUE_APP_BASE_API + '/file/upload',
|
||||||
dialogInnerVisible: false,
|
dialogInnerVisible: false,
|
||||||
fileType: ["png", "jpg", "jpeg"],
|
fileType: ['png', 'jpg', 'jpeg'],
|
||||||
previewUrl: "",
|
previewUrl: '',
|
||||||
addSwiperVisible: false,
|
addSwiperVisible: false,
|
||||||
value1: true,
|
value1: true,
|
||||||
value2: true,
|
value2: true,
|
||||||
addSwiperFormRules: {},
|
addSwiperFormRules: {},
|
||||||
addSwiperForm: {
|
addSwiperForm: {
|
||||||
fileList: [],
|
fileList: [],
|
||||||
slidePicture: "",
|
slidePicture: '',
|
||||||
slideLink: "",
|
slideLink: '',
|
||||||
delFlag: true,
|
delFlag: true,
|
||||||
},
|
},
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + getToken(),
|
Authorization: 'Bearer ' + getToken(),
|
||||||
},
|
},
|
||||||
swiperList: [
|
swiperList: [],
|
||||||
{
|
}
|
||||||
imgSrc: "xxxx",
|
},
|
||||||
isShow: true,
|
created() {
|
||||||
outLink: "xxxx999",
|
this.getSwiperListData()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleAdd() {
|
||||||
|
this.addSwiperVisible = true
|
||||||
},
|
},
|
||||||
{
|
// 获取列表
|
||||||
imgSrc: "xxxx",
|
async getSwiperListData() {
|
||||||
isShow: true,
|
const res = await getSwiperListApi()
|
||||||
outLink: "xxxx999",
|
this.swiperList = res.rows
|
||||||
|
|
||||||
|
this.swiperList.forEach((e) => {
|
||||||
|
e.delFlag == 0 ? (e.delFlag = true) : (e.delFlag = false)
|
||||||
|
})
|
||||||
|
// console.log(res, "列表数据--");
|
||||||
},
|
},
|
||||||
{
|
async submitForm() {
|
||||||
imgSrc: "xxxx",
|
// 组装参数
|
||||||
isShow: false,
|
const { slidePicture, slideLink, delFlag } = this.addSwiperForm
|
||||||
outLink: "xxxx999",
|
const params = {
|
||||||
|
slidePicture,
|
||||||
|
slideLink,
|
||||||
|
delFlag: delFlag ? 0 : 2,
|
||||||
|
}
|
||||||
|
const res = await addHomeSwiperApi(params)
|
||||||
|
if (res.code === 200) {
|
||||||
|
this.$modal.msgSuccess('新增成功')
|
||||||
|
this.$refs.addSwiperFormRef.resetFields()
|
||||||
|
this.addSwiperVisible = false
|
||||||
|
this.getSwiperListData()
|
||||||
|
}
|
||||||
|
// console.log(res, "上传结果--");
|
||||||
|
// this.addSwiperVisible = false;
|
||||||
|
},
|
||||||
|
cancel() {
|
||||||
|
this.addSwiperVisible = false
|
||||||
|
},
|
||||||
|
// 上传之前
|
||||||
|
handleBeforeUpload(file) {
|
||||||
|
const isSvg = this.fileType.some((e) => file.type.includes(e))
|
||||||
|
if (!isSvg) {
|
||||||
|
this.$modal.msgError(
|
||||||
|
`文件格式不正确, 请上传${this.fileType.join(
|
||||||
|
'、',
|
||||||
|
)}格式的文件!`,
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const isLt = file.size / 1024 / 1024 < 10
|
||||||
|
if (!isLt) {
|
||||||
|
this.$modal.msgError(`图片大小不能超过 10 MB`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
this.$modal.loading('图片正在上传,请稍候...')
|
||||||
|
},
|
||||||
|
// 移除
|
||||||
|
handleRemove(file) {
|
||||||
|
this.addSwiperForm.fileList = this.addSwiperForm.fileList.filter(
|
||||||
|
(item) => item.uid !== file.uid,
|
||||||
|
)
|
||||||
|
this.addSwiperForm.slidePicture = ''
|
||||||
|
},
|
||||||
|
// 预览 图片
|
||||||
|
handlePreview(file) {
|
||||||
|
this.dialogInnerVisible = true
|
||||||
|
this.previewUrl = file.url
|
||||||
},
|
},
|
||||||
],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.getSwiperListData();
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
handleAdd() {
|
|
||||||
this.addSwiperVisible = true;
|
|
||||||
},
|
|
||||||
// 获取列表
|
|
||||||
async getSwiperListData() {
|
|
||||||
const res = await getSwiperListApi();
|
|
||||||
this.swiperList = res.rows;
|
|
||||||
|
|
||||||
this.swiperList.forEach((e) => {
|
// 文件个数超出限制
|
||||||
e.delFlag == 0 ? (e.delFlag = true) : (e.delFlag = false);
|
handleExceed() {
|
||||||
});
|
this.$modal.msgError(`上传的图片数量不能超过 1 个`)
|
||||||
// console.log(res, "列表数据--");
|
},
|
||||||
},
|
// 上传成功
|
||||||
async submitForm() {
|
handleSuccess(res) {
|
||||||
// 组装参数
|
if (res.code === 200) {
|
||||||
const { slidePicture, slideLink, delFlag } = this.addSwiperForm;
|
this.addSwiperForm.slidePicture = res.data.url
|
||||||
const params = {
|
} else {
|
||||||
slidePicture,
|
this.$modal.msgError('上传失败')
|
||||||
slideLink,
|
this.addSwiperForm.fileList = []
|
||||||
delFlag: delFlag ? 0 : 2,
|
this.addSwiperForm.slidePicture = ''
|
||||||
};
|
}
|
||||||
const res = await addHomeSwiperApi(params);
|
this.$modal.closeLoading()
|
||||||
if (res.code === 200) {
|
},
|
||||||
this.$modal.msgSuccess("新增成功");
|
|
||||||
this.$refs.addSwiperFormRef.resetFields();
|
|
||||||
this.addSwiperVisible = false;
|
|
||||||
this.getSwiperListData();
|
|
||||||
}
|
|
||||||
// console.log(res, "上传结果--");
|
|
||||||
// this.addSwiperVisible = false;
|
|
||||||
},
|
|
||||||
cancel() {
|
|
||||||
this.addSwiperVisible = false;
|
|
||||||
},
|
|
||||||
// 上传之前
|
|
||||||
handleBeforeUpload(file) {
|
|
||||||
const isSvg = this.fileType.some((e) => file.type.includes(e));
|
|
||||||
if (!isSvg) {
|
|
||||||
this.$modal.msgError(
|
|
||||||
`文件格式不正确, 请上传${this.fileType.join("、")}格式的文件!`
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const isLt = file.size / 1024 / 1024 < 10;
|
|
||||||
if (!isLt) {
|
|
||||||
this.$modal.msgError(`图片大小不能超过 10 MB`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.$modal.loading("图片正在上传,请稍候...");
|
|
||||||
},
|
|
||||||
// 移除
|
|
||||||
handleRemove(file) {
|
|
||||||
this.addSwiperForm.fileList = this.addSwiperForm.fileList.filter(
|
|
||||||
(item) => item.uid !== file.uid
|
|
||||||
);
|
|
||||||
this.addSwiperForm.slidePicture = "";
|
|
||||||
},
|
|
||||||
// 预览 图片
|
|
||||||
handlePreview(file) {
|
|
||||||
this.dialogInnerVisible = true;
|
|
||||||
this.previewUrl = file.url;
|
|
||||||
},
|
|
||||||
|
|
||||||
// 文件个数超出限制
|
onClickDelete(row) {
|
||||||
handleExceed() {
|
this.$confirm('确定删除该轮播图吗?', '提示', {
|
||||||
this.$modal.msgError(`上传的图片数量不能超过 1 个`);
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
})
|
||||||
|
.then(async () => {
|
||||||
|
const res = await deleteHomeSwiperApi(row.id)
|
||||||
|
if (res.code === 200) {
|
||||||
|
this.$modal.msgSuccess('删除成功')
|
||||||
|
this.getSwiperListData()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
},
|
||||||
|
async onSwitchChange(val, row) {
|
||||||
|
const { id } = row
|
||||||
|
const params = {
|
||||||
|
id,
|
||||||
|
delFlag: val ? 0 : 2,
|
||||||
|
}
|
||||||
|
const res = await editHomeSwiperTypeApi(params)
|
||||||
|
if (res.code === 200) {
|
||||||
|
this.$modal.msgSuccess('状态修改成功')
|
||||||
|
this.getSwiperListData()
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// 上传成功
|
}
|
||||||
handleSuccess(res) {
|
|
||||||
if (res.code === 200) {
|
|
||||||
this.addSwiperForm.slidePicture = res.data.url;
|
|
||||||
} else {
|
|
||||||
this.addSwiperForm.fileList = [];
|
|
||||||
this.addSwiperForm.slidePicture = "";
|
|
||||||
}
|
|
||||||
this.$modal.closeLoading();
|
|
||||||
},
|
|
||||||
|
|
||||||
onClickDelete(row) {
|
|
||||||
this.$confirm("确定删除该轮播图吗?", "提示", {
|
|
||||||
confirmButtonText: "确定",
|
|
||||||
cancelButtonText: "取消",
|
|
||||||
type: "warning",
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
console.log(row, "row-");
|
|
||||||
})
|
|
||||||
.catch(() => {});
|
|
||||||
},
|
|
||||||
async onSwitchChange(val, row) {
|
|
||||||
console.log(row, "列表消息");
|
|
||||||
const { id } = row;
|
|
||||||
const params = {
|
|
||||||
id,
|
|
||||||
delFlag: val ? 0 : 2,
|
|
||||||
};
|
|
||||||
const res = await editHomeSwiperTypeApi(params);
|
|
||||||
if (res.code === 200) {
|
|
||||||
this.$modal.msgSuccess("状态修改成功");
|
|
||||||
this.getSwiperListData();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue