Oss对象存储,以及品牌增删改查

master
20300 2024-03-07 15:32:51 +08:00
parent 7456f75612
commit 29f7d2bb11
3 changed files with 296 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import request from '@/utils/request'
export function insertBrand(brandInfo) {
return request({
url: '/product/brandInfo/insertBrand',
method: 'post',
data: brandInfo
})
}
export function getBrandList(likeName) {
return request({
url: '/product/brandInfo/getBrandList?likeName='+likeName,
method: 'get'
})
}
export function deleteBrandInfo(brandId) {
return request({
url: '/product/brandInfo/deleteBrandInfo',
method: 'get',
brandId
})
}

View File

@ -0,0 +1,172 @@
<template>
<div>
<el-table
:data="brandList"
style="width: 100%">
<el-table-column
label="品牌名称"
width="180">
<template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row.name }}</span>
</template>
</el-table-column>
<el-table-column
label="品牌logo"
width="180">
<template slot-scope="scope">
<img :src="scope.row.logo" alt="图片损坏">
</template>
</el-table-column>
<el-table-column
label="简单描述"
width="180">
<template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row.introduction }}</span>
</template>
</el-table-column>
<el-table-column
label="创建人"
width="180">
<template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row.createBy }}</span>
</template>
</el-table-column>
<el-table-column
label="创建日期"
width="180">
<template slot-scope="scope">
<i class="el-icon-time"></i>
<span style="margin-left: 10px">{{ scope.row.createTime }}</span>
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleEdit(scope.$index, scope.row)">编辑</el-button>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-button type="primary" size="mini" @click="isInsertBrandOpen = true">添加品牌</el-button>
<el-dialog title="品牌信息" :visible.sync="isInsertBrandOpen">
<el-form ref="form" :model="insertBrandReg" label-width="80px">
<el-form-item label="品牌名称">
<el-input v-model="insertBrandReg.name"></el-input>
</el-form-item>
<el-form-item label="品牌logo">
<upload-pic ref="uploadPic" @handle-image-url="handleImageUrl"></upload-pic>
</el-form-item>
<el-form-item label="简介" prop="remark">
<el-input v-model="insertBrandReg.introduction" placeholder="请输入内容" type="textarea"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="isInsertBrandOpen = false"> </el-button>
<el-button type="primary" @click="insertBrandInfo"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
//jsjsjson,
//import from ',
import UploadPic from "@/views/product/upload/uploadPic.vue";
import {deleteBrandInfo, getBrandList, insertBrand} from "@/api/product/brand";
export default {
name: "brand",
//import使"
components: {
UploadPic,
},
props: {},
data() {
//"
return {
imageUrl: "",
insertBrandReg:{},
isInsertBrandOpen: false,
brandList: [],
brandName: ""
};
},
// data",
computed: {},
//data",
watch: {},
//",
methods: {
handleEdit(index, row) {
this.isInsertBrandOpen = true
this.insertBrandReg = row
console.log(index, row);
},
handleDelete(index, row) {
deleteBrandInfo(row.id).then(
res =>{
this.$message.success(res.msg)
this.getBrandList()
}
)
console.log(index, row);
},
getBrandList() {
getBrandList(this.brandName).then(
res =>{
this.brandList = res.data
}
)
},
insertBrandInfo() {
insertBrand(this.insertBrandReg).then(
res => {
console.log("添加品牌的结果是:",res)
this.$message.success(res.msg)
this.insertBrandReg = {}
this.imageUrl = ""
this.isInsertBrandOpen = false
this.getBrandList()
}
)
},
handleImageUrl() {
console.log("六六六")
const imageUrl = this.$refs.uploadPic.imageUrl;
this.insertBrandReg.logo = imageUrl
console.log("获取到的图片地址:", imageUrl);
},
},
// - 访this",
created() {
this.getBrandList()
},
// - 访DOM",
mounted() {
},
beforeCreate() {
}, // - ",
beforeMount() {
}, // - ",
beforeUpdate() {
}, // - ",
updated() {
}, // - ",
beforeDestroy() {
}, // - ",
destroyed() {
}, // - ",
activated() {
} //keep-alive",
};
</script>
<style scoped>
</style>

View File

@ -0,0 +1,100 @@
<template>
<div>
<el-upload
style="width: auto; height: auto"
class="avatar-uploader"
action="http://localhost:9209/upload/uploadPic"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload">
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</div>
</template>
<script>
//jsjsjson,
//import from ',
export default {
name: "uploadPic",
//import使"
components: {},
props: {},
data() {
//"
return {
imageUrl: ""
};
},
// data",
computed: {},
//data",
watch: {},
//",
methods: {
handleAvatarSuccess(res, file) {
console.log(res,file)
this.imageUrl =res.data
this.$emit('handle-image-url', this.imageUrl);
},
beforeAvatarUpload(file) {
const isLt2M = file.size / 1024 / 1024 < 10;
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 10MB!');
}
return isLt2M;
}
},
// - 访this",
created() {
},
// - 访DOM",
mounted() {
},
beforeCreate() {
}, // - ",
beforeMount() {
}, // - ",
beforeUpdate() {
}, // - ",
updated() {
}, // - ",
beforeDestroy() {
}, // - ",
destroyed() {
}, // - ",
activated() {
} //keep-alive",
};
</script>
<style scoped>
.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>