<template>
|
<view class="container">
|
<view class='initiae-box'>
|
<u-form :model="form" ref="uForm">
|
|
<u-form-item label-position='top' prop="content" label="指令内容" :required="true">
|
<u-input type='textarea' v-model="form.content" placeholder="请输入指令内容" />
|
</u-form-item>
|
|
<u-form-item label-position='top' label="指令相关图片" class='imgissue-upload'>
|
<!-- <u-upload :action="action" :file-list="fileList" max-count='1'></u-upload> -->
|
<seeImgs :imgs="imgs" :videos="[]" @del="delImg" :type="'imgs'"></seeImgs>
|
<image style="width: 4rem; height: 4rem; display: block;" @tap="takePhoto" src="../../static/images/upload.png" mode=""></image>
|
</u-form-item>
|
|
|
</u-form>
|
<view>
|
<u-button type="primary" @click="initiateClick">发送</u-button>
|
</view>
|
<view>
|
<u-toast ref="uToast" />
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import seeImgs from '../../components/seeImges/seeImges.vue';
|
export default {
|
components: {
|
seeImgs
|
},
|
data() {
|
return {
|
action: 'http://192.168.0.108:81/blade-resource/oss/endpoint/put-file',
|
fileList: [{
|
url: 'http://pics.sc.chinaz.com/files/pic/pic9/201912/hpic1886.jpg',
|
}],
|
|
form: {
|
content: '',
|
|
},
|
rules: {
|
|
content: [{
|
min: 5,
|
required: true,
|
message: '指令内容不能少于5个字',
|
trigger: ['change', 'blur'],
|
}]
|
},
|
imgs: [],
|
};
|
},
|
onLoad() {
|
console.log(this.$store.state)
|
},
|
onReachBottom() {
|
|
},
|
mounted() {},
|
onReady() {
|
this.$refs.uForm.setRules(this.rules);
|
},
|
methods: {
|
|
initiateClick() {
|
this.$refs.uForm.validate(valid => {
|
if (valid) {
|
uni.request({
|
url: this.$store.state.piAPI + "/directive/saveDirectiveAndFile",
|
method: "post",
|
data: {
|
// 接收
|
receiveDirectiveIds: this.$store.state
|
.UserData.user_id,
|
// 发送
|
sendDirectiveId: this.$store.state
|
.UserData.user_id,
|
content: this.form.content,
|
sendTime: "2021-07-22 12:00:00",
|
|
},
|
success: (res) => {
|
if (res.data.msg == "操作成功") {
|
// this.$refs.uToast.show({
|
// title: '发送成功',
|
// type: 'success',
|
// url: '/pages/report/report'
|
// })
|
}
|
}
|
});
|
} else {
|
console.log('验证失败');
|
}
|
});
|
},
|
//图片删除
|
delImg(index) {
|
this.imgs.splice(index, 1);
|
},
|
//图片上传
|
takePhoto() {
|
var that = this;
|
uni.chooseImage({
|
count: 3, //可选择数量,默认9
|
sizeType: ['compressed', 'original'], //上传压缩图,原图
|
sourceType: ['album', 'camera'], //从相册选择或从使用相机
|
success: async (res) => {
|
for (var i = 0; i < res.tempFiles.length; i++) {
|
if (res.tempFiles[i].size > 10 * 1024 * 1000) { //上传图片大小限制
|
uni.showToast({
|
title: "照片大小不能超过10MB",
|
icon: "none"
|
})
|
return
|
}
|
}
|
var tempFilePath = res.tempFilePaths;
|
// try {
|
uni.showLoading({
|
title: "上传中...",
|
mask: true
|
})
|
var that = this;
|
// 循环调用uni.uploadFile ,因微信小程序只支持单文件上传
|
for (var i = 0; i < tempFilePath.length; i++) {
|
uni.uploadFile({
|
// url: 'https://web.byisf.com/api/blade-jfpts/depl/put-depl', //仅为示例,非真实的接口地址
|
url: 'http://192.168.0.108:81/blade-resource/oss/endpoint/put-file',
|
filePath: tempFilePath[i],
|
name: 'file',
|
formData: {
|
'user': 'test' // 上传附带参数
|
},
|
success: (data) => {
|
uni.showToast({
|
title: '上传图片成功!',
|
duration: 1000
|
});
|
// 根据接口具体返回格式 赋值具体对应url
|
that.imgs.push({
|
id: i,
|
src: JSON.parse(data.data).data
|
})
|
}
|
});
|
}
|
}
|
});
|
},
|
|
|
}
|
};
|
</script>
|
|
|
<style lang="scss">
|
.initiae-box {
|
padding: 0 30rpx;
|
}
|
</style>
|