作者 小范

crm管理界面优化+出勤车辆上传图片完善+车辆定位新增图片展示功能

... ... @@ -7,6 +7,8 @@ const serviceName = '/cloud-user-center'
//车辆定位
export const selectVehicle = params => { return axios.get(`${baseServiceURL}/map/location/lastlocation`, { params: params }); };
export const selectByliscenNo = params => { return axios.get(`${baseServiceURL}/map/location/selectByliscenNo`, { params: params }); };
//出任务
export const insertSelective = params => { return http.post(`${baseServiceURL}/map/location/insertSelective`, params); };
//获取用户列表
... ... @@ -21,6 +23,8 @@ export const selectHistroy = params => { return axios.get(`${baseServiceURL}/map
//出勤车辆
export const selectList = params => { return axios.get(`${baseServiceURL}/map/location/selectList`, { params: params }); };
export const DoneTask = params => { return http.post(`${baseServiceURL}/map/location/DoneTask`, params); };
export const UploadImage = params => { return http.postMulData(`${baseServiceURL}/map/location/upload`, params); };
//根据用户查询所属出勤车辆
export const selectNameList = params => { return axios.get(`${baseServiceURL}/map/location/selectNameList`, { params: params }); };
... ...
... ... @@ -38,6 +38,16 @@ export default {
}],
})
},
postMulData(url, data) {
return axios({
method: 'POST', // 请求协议
url: url, // 请求的地址
data: data, // post 请求的数据
headers: {
'Content-Type': 'multipart/form-data'
}
})
},
get(url, params) {
return axios({
method: 'GET',
... ...
... ... @@ -50,7 +50,7 @@
width="220">
<template slot-scope="scope">
<el-button type="danger" size="mini" @click="applyEnd(scope.row)">结束出勤</el-button>
<el-button type="success" @click="centerDialogVisible = true">图片上传</el-button>
<el-button type="success" @click="uploadImg(scope.row)">图片上传</el-button>
</template>
</el-table-column>
</el-table>
... ... @@ -73,30 +73,23 @@
width="30%"
center>
<div>
<el-upload
class="avatar-uploader"
action="https://jsonplaceholder.typicode.com/posts/"
: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>
<el-input v-model="description" placeholder="请输入图片描述"></el-input>
</div>
<!-- 图片选择 -->
<input type="file" ref="fileInput" accept="image/*" @change="handleFileChange" style="display: none;">
<el-button type="primary" @click="chooseFile">选择图片</el-button>
<span v-if="selectedFileName" style="margin-left: 10px;">已选择文件: {{ selectedFileName }}</span>
<!-- 图片描述输入框 -->
<el-input v-model="imageDescription" placeholder="请输入图片描述" style="margin-top: 20px;"></el-input>
<span slot="footer" class="dialog-footer">
<el-button @click="centerDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
</span>
<!-- 上传按钮 -->
<el-button type="success" @click="uploadImage" style="margin-top: 20px;">上传图片</el-button>
</div>
</el-dialog>
</el-card>
</el-row>
</template>
<script>
import {selectList,DoneTask} from '../../api/consigner/vehicle';
import {selectList,DoneTask,UploadImage} from '../../api/consigner/vehicle';
export default {
data() {
... ... @@ -114,25 +107,56 @@
formInline: {
user: '',
},
imageUrl: '',
description:''
imageDescription: '', // 图片描述
selectedFile: null, // 用户选择的文件
selectedFileName: '', // 用户选择的文件名
id:'',
}
},
methods: {
handleAvatarSuccess(res, file) {
this.imageUrl = URL.createObjectURL(file.raw);
uploadImg(row){this.id=row.id;this.centerDialogVisible=true;},
// 选择图片
chooseFile() {
this.$refs.fileInput.click();
},
beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg';
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isJPG) {
this.$message.error('上传头像图片只能是 JPG 格式!');
// 文件改变时触发
handleFileChange(event) {
this.selectedFile = event.target.files[0];
this.selectedFileName = this.selectedFile ? this.selectedFile.name : '';
},
// 上传图片
uploadImage() {
if(this.selectedFile == null){
return this.$message.error('请上传图片')
}
if(this.imageDescription == null||this.imageDescription == ''){
return this.$message.error('请输入描述')
}
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2MB!');
if (!this.selectedFile) {
this.$message.warning('请选择图片');
return;
}
return isJPG && isLt2M;
// 创建 FormData 对象,用于上传文件
const formData = new FormData();
formData.append('file', this.selectedFile);
formData.append('desc', this.imageDescription);
formData.append('id',this.id);
UploadImage(formData).then((response) => {
const res = response.data
console.log(response.data)
if (res.code !== '200') {
return _this.$message.error(res.data)
}
this.$message.success(res.data)
this.centerDialogVisible=false;
this.selectedFile=null;
this.imageDescription='';
this.selectedFileName='';
}).catch(error => {
// 关闭加载
this.$message.error(error.toString())
})
},
handleSizeChange(val) {
this.queryInfo.pageSize = val
... ...
... ... @@ -41,13 +41,29 @@
</div>
</el-form-item>
</el-col>
<el-col :span="3">
<el-col :span="2">
<el-button type="primary" icon="el-icon-search" size="mini" @click="getList()">
查询
</el-button>
</el-col>
<el-col :span="2">
<el-button @click="getByliscenNo()" type="success" style="margin-left: 16px;">
车辆图片
</el-button>
</el-col>
</el-form>
</el-row>
<el-drawer
title="车辆图片"
:visible.sync="drawer"
:with-header="false">
<div>
<div v-for="(imageInfo, index) in imageInfos" :key="index" class="image-container">
<img v-if="imageInfo && imageInfo.url" :src="imageInfo.url" alt="Image" class="image" />
<p v-if="imageInfo && imageInfo.content">{{ imageInfo.content }}</p>
</div>
</div>
</el-drawer>
</el-card>
</el-row>
<div id="mapContainer" style="width: 100%; height: 500px;"></div>
... ... @@ -55,13 +71,14 @@
</template>
<script>
import AMapLoader from '@amap/amap-jsapi-loader';
import { selectVehicle,selectNameList } from '../../api/consigner/vehicle';
import {selectVehicle, selectNameList, selectByliscenNo, selectList} from '../../api/consigner/vehicle';
import {loginedUserInfo} from "../../api/user";
export default {
name: 'MapComponent',
data() {
return {
drawer: false,
mapInstance: null,
queryInfo: {
vno: '',
... ... @@ -69,6 +86,8 @@
},
vnos:[],
loading:false,
imageUrls: [], // 存储图片地址的数组
imageInfos:[],
rules: {
vno: [
{ required: true, message: '请输入车牌号', trigger: 'blur' },
... ... @@ -81,6 +100,34 @@
};
},
methods: {
//获取图片
getByliscenNo(){
if(this.queryInfo.vno == null||this.queryInfo.vno ==''){
return this.$message.error('请选择车牌号')
}
this.drawer = true;
selectByliscenNo({lisenceNo:this.queryInfo.vno}).then((response) => {
const res = response.data
console.log(response.data)
if (res.code !== '200') {
return this.$message.error('获取消息收发记录,失败!')
}
this.imageInfos = res.data.imgurl.split(',').map(url => {
if (url !== 'null') {
const parts = url.split('/');
const fileName = parts.pop();
const content = fileName.split('-')[0];
return {
url: url,
content: content
};
}
});
}).catch(error => {
// 关闭加载
this.$message.error(error.toString())
})
},
//获取车牌号
getCreden(){
this.vnos=[];
... ... @@ -181,6 +228,14 @@
}
</style>
<style>
.image-container {
margin-bottom: 10px;
}
.image {
max-width: 100%;
max-height: 200px;
}
.my-text-area .el-textarea__inner{
min-height: 28px;
height: 28px;
... ...
... ... @@ -106,14 +106,14 @@
</el-table-column>
<el-table-column prop="departmentid" label="简码" min-width="150" >
</el-table-column>
<el-table-column label="操作" min-width="260" fixed="right">
<el-table-column label="操作" min-width="200" fixed="right">
<template slot-scope="scope">
<!-- <el-row>-->
<!-- <el-button type="success" @click="handleAdd(scope.$index, scope.row)">新增下级</el-button>-->
<!-- <el-button @click="setPerm(scope.$index, scope.row)">设置权限</el-button>-->
<!-- </el-row>-->
<el-row>
<el-button @click="handleEdit(scope.$index, scope.row)">编&emsp;&emsp;辑</el-button>
<el-button type="success" @click="handleEdit(scope.$index, scope.row)">编&emsp;&emsp;辑</el-button>
<el-button type="danger" @click="handleDel(scope.$index, scope.row)">删&emsp;&emsp;除</el-button>
</el-row>
</template>
... ... @@ -287,6 +287,9 @@
],
type: [
{ required: true, message: '请选择组织机构类型', trigger: 'blur' }
],
departmentid:[
{ required: true, message: '请输入承运人代码', trigger: 'blur' }
]
},
//新增界面数据
... ...