|
@@ -1,9 +1,9 @@
|
|
|
<template>
|
|
|
- <view>
|
|
|
+ <view class="main">
|
|
|
<view class="bg-white default_title">
|
|
|
<u--form :model="inputForm" labelWidth="130px" class="u-form default_title" labelPosition="left"
|
|
|
ref="inputForm">
|
|
|
- <u-form-item label="年度" borderBottom prop="yearNum">
|
|
|
+ <u-form-item label="年度" borderBottom prop="yearNum">
|
|
|
<u--input readonly v-model="inputForm.yearNum" placeholder="输入年度" border="none"></u--input>
|
|
|
</u-form-item>
|
|
|
<u-form-item label="卡号" borderBottom prop="cardNum">
|
|
@@ -12,9 +12,9 @@
|
|
|
</u--form>
|
|
|
</view>
|
|
|
<view class="bg-white margin-top main_info">
|
|
|
- <u--form :model="inputForm" labelWidth="130px" class="u-form default_title" labelPosition="left"
|
|
|
- ref="inputForm">
|
|
|
- <u-form-item label="来文机关" borderBottom prop="sendingAgency">
|
|
|
+ <u--form :model="inputForm" :rules="rules" labelWidth="130px" class="u-form default_title"
|
|
|
+ labelPosition="left" ref="inputForm">
|
|
|
+ <u-form-item required label="来文机关" borderBottom prop="sendingAgency">
|
|
|
<u--input v-model="inputForm.sendingAgency" placeholder="请输入来文机关" border="none"></u--input>
|
|
|
</u-form-item>
|
|
|
<u-form-item label="来文字号" borderBottom prop="docFontSize">
|
|
@@ -23,15 +23,15 @@
|
|
|
<u-form-item label="文件来源" borderBottom prop="fileSource">
|
|
|
<u--input v-model="inputForm.fileSource" placeholder="请输入文件来源" border="none"></u--input>
|
|
|
</u-form-item>
|
|
|
- <u-form-item label="成文时间" borderBottom prop="writtenTime" @click="openDate(1)">
|
|
|
+ <u-form-item label="成文时间" borderBottom prop="writtenTime">
|
|
|
<jp-datetime-picker :show="iswrite" v-model="inputForm.writtenTime" placeholder="选择成文时间"
|
|
|
mode="date"></jp-datetime-picker>
|
|
|
</u-form-item>
|
|
|
- <u-form-item label="收文时间" borderBottom prop="receivingTime" @click="openDate(2)">
|
|
|
+ <u-form-item label="收文时间" borderBottom prop="receivingTime">
|
|
|
<jp-datetime-picker :show="isreceive" v-model="inputForm.receivingTime" placeholder="选择收文时间"
|
|
|
mode="date"></jp-datetime-picker>
|
|
|
</u-form-item>
|
|
|
- <u-form-item label="内容摘要" borderBottom prop="contentSummary">
|
|
|
+ <u-form-item required label="内容摘要" borderBottom prop="contentSummary">
|
|
|
<u--textarea v-model="inputForm.contentSummary" placeholder="请输入内容摘要" border="none"></u--textarea>
|
|
|
</u-form-item>
|
|
|
<u-form-item label="来文附件" prop="attachedDocumentId" labelPosition="top">
|
|
@@ -39,7 +39,11 @@
|
|
|
height="150" accept="file" :previewImage="false">
|
|
|
<view class="addfile flex"> <u-icon size="20" bold name="plus"></u-icon></view>
|
|
|
</u-upload>
|
|
|
+ <u-upload :fileList="fileLists" @afterRead="afterRead" multiple :maxCount="9" width="80" height="80"
|
|
|
+ accept="image" capture="camera" :previewImage="false">
|
|
|
+ </u-upload>
|
|
|
</u-form-item>
|
|
|
+ <view class="text-danger" style="font-size: 12px!important;">请确保上传图片内容清晰可见,所有涉密敏感信息不得上传</view>
|
|
|
<view class="other_info">
|
|
|
<view class="other_pdf">
|
|
|
<u-cell-group>
|
|
@@ -52,7 +56,7 @@
|
|
|
</view>
|
|
|
<u-upload :fileList="imgList" @delete="deletePic" multiple :maxCount="imgList.length"
|
|
|
:previewFullImage="true"></u-upload>
|
|
|
- <u--text size="10" type="error" text="请确保上传图片内容清晰可见,所有涉密敏感信息不得上传"></u--text>
|
|
|
+
|
|
|
<view class="submit_btn flex">
|
|
|
<u-button v-if="!loading" type="primary" text="提交新增" @click="formSubmit"></u-button>
|
|
|
<u-button v-if="loading" :loading="loading" type="primary" text="加载中"></u-button>
|
|
@@ -60,7 +64,11 @@
|
|
|
</u--form>
|
|
|
</view>
|
|
|
<u-toast ref="uToast"></u-toast>
|
|
|
-
|
|
|
+ <u-overlay :show="loading">
|
|
|
+ <view class="warp">
|
|
|
+ <view class="rect"><u-button plain loading loadingText="加载中"></u-button></view>
|
|
|
+ </view>
|
|
|
+ </u-overlay>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
@@ -75,13 +83,14 @@
|
|
|
import gwCirculationCard2Service from '@/api/circulation/gwCirculationCard2.js'
|
|
|
export default {
|
|
|
mounted() {
|
|
|
- gwCirculationCard2Service.getCardNum().then(data =>{
|
|
|
+ gwCirculationCard2Service.getCardNum().then(data => {
|
|
|
const currentYear = new Date().getFullYear();
|
|
|
this.inputForm.yearNum = currentYear
|
|
|
- this.inputForm.cardNum = "["+currentYear +"]"+data+"号"
|
|
|
+ this.cardNum = data
|
|
|
+ this.inputForm.cardNum = "[" + currentYear + "]" + data + "号"
|
|
|
this.inputForm.writtenTime = moment().format('YYYY-MM-DD');
|
|
|
this.inputForm.receivingTime = moment().format('YYYY-MM-DD');
|
|
|
- })
|
|
|
+ })
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
@@ -92,6 +101,7 @@
|
|
|
fileLists: [],
|
|
|
fileList: [],
|
|
|
imgList: [],
|
|
|
+ cardNum: "",
|
|
|
inputForm: {
|
|
|
id: '',
|
|
|
yearNum: '',
|
|
@@ -106,19 +116,24 @@
|
|
|
remark: '',
|
|
|
state: '1'
|
|
|
},
|
|
|
+ rules: {
|
|
|
+ sendingAgency: [{
|
|
|
+ required: true,
|
|
|
+ message: '请输入来问机关',
|
|
|
+ trigger: ['blur', 'change']
|
|
|
+ }],
|
|
|
+ contentSummary: [{
|
|
|
+ required: true,
|
|
|
+ message: '请输入内容摘要',
|
|
|
+ trigger: ['blur', 'change']
|
|
|
+ }]
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- // 打开日期
|
|
|
- openDate(type) {
|
|
|
- console.log("c====", type);
|
|
|
- if (type == 1) {
|
|
|
- this.iswrite = !this.iswrite
|
|
|
- } else if (type == 2) {
|
|
|
- this.isreceive = !this.isreceive
|
|
|
- }
|
|
|
- },
|
|
|
+
|
|
|
showToast(params) {
|
|
|
+ this.loading = false
|
|
|
this.$refs.uToast.show({
|
|
|
...params,
|
|
|
complete() {
|
|
@@ -151,83 +166,70 @@
|
|
|
this[`fileLists${event.name}`].splice(event.index, 1)
|
|
|
},
|
|
|
// 图片压缩
|
|
|
- compressH5(urlData) {
|
|
|
+ compressH5(urlData, targetSizeKB, initialQuality = 1.0) {
|
|
|
+ const maxQuality = 1.0;
|
|
|
+ const minQuality = 0.0;
|
|
|
+ const tolerance = 0.01; // 根据需要调整公差
|
|
|
let that = this
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- let a = uni.getImageInfo({
|
|
|
- src: urlData.url,
|
|
|
- success(res) {
|
|
|
- let originWidth = res.width; //图片原始宽
|
|
|
- let originHeight = res.height; //图片原始高
|
|
|
- let maxWidth = 800;
|
|
|
- let maxHeight = 800;
|
|
|
- let img = new Image()
|
|
|
- img.src = res.path
|
|
|
- let canvas = document.createElement('canvas');
|
|
|
- let ctx = canvas.getContext('2d')
|
|
|
- // 目标尺寸
|
|
|
- let targetWidth = originWidth;
|
|
|
- let targetHeight = originHeight;
|
|
|
+ let binarySearch = (min, max) => {
|
|
|
+ const midQuality = (min + max) / 2;
|
|
|
+ uni.getImageInfo({
|
|
|
+ src: urlData.url,
|
|
|
+ success(res) {
|
|
|
+ let img = new Image()
|
|
|
+ img.src = res.path
|
|
|
+ img.onload = function() {
|
|
|
+ const canvas = document.createElement('canvas');
|
|
|
+ const ctx = canvas.getContext('2d');
|
|
|
|
|
|
- canvas.width = targetWidth
|
|
|
- canvas.height = targetHeight
|
|
|
- // 图片压缩
|
|
|
- ctx.drawImage(img, 0, 0, targetWidth, targetHeight)
|
|
|
- // canvas对图片进行缩放 0.3是我定义的图片质量,
|
|
|
- let base64 = canvas.toDataURL(urlData.type, 0.3);
|
|
|
- // 将base64转换为file流,
|
|
|
-
|
|
|
- let file = that.convertBase64UrlToFile({
|
|
|
- url: base64,
|
|
|
- type: urlData.type,
|
|
|
- name: urlData.name
|
|
|
- })
|
|
|
-
|
|
|
- urlData.size = file.size
|
|
|
- let result = that.uploadFilePromise(urlData)
|
|
|
- setTimeout(() => {
|
|
|
- resolve(result)
|
|
|
- }, 1000)
|
|
|
- },
|
|
|
- fail() {
|
|
|
- uni.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '图片压缩失败',
|
|
|
- showCancel: false
|
|
|
- });
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- convertBase64UrlToFile(base64) {
|
|
|
- let urlData = base64.url
|
|
|
- let type = base64.type
|
|
|
- let contentName = base64.name
|
|
|
- let bytes = null
|
|
|
- if (urlData.split(',').length > 1) { //是否带前缀
|
|
|
- bytes = window.atob(urlData.split(',')[1]) // 去掉url的头,并转换为byte
|
|
|
- } else {
|
|
|
- bytes = window.atob(urlData)
|
|
|
- }
|
|
|
- // 处理异常,将ascii码小于0的转换为大于0
|
|
|
- let ab = new ArrayBuffer(bytes.length)
|
|
|
- let ia = new Uint8Array(ab)
|
|
|
- for (let i = 0; i < bytes.length; i++) {
|
|
|
- ia[i] = bytes.charCodeAt(i)
|
|
|
- }
|
|
|
- let result = new Blob([ab], {
|
|
|
- type: type,
|
|
|
- })
|
|
|
- let result1 = new File([result], contentName, {
|
|
|
- type: type
|
|
|
+ canvas.width = img.width;
|
|
|
+ canvas.height = img.height;
|
|
|
+
|
|
|
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
|
+
|
|
|
+ // 使用异步的 toBlob 方法
|
|
|
+ canvas.toBlob(async (blob) => {
|
|
|
+ const fileSizeKB = blob.size / 1024;
|
|
|
+ if (Math.abs(fileSizeKB - targetSizeKB) <
|
|
|
+ tolerance || max - min < tolerance) {
|
|
|
+ // 当前质量足够接近目标大小,使用当前质量解析
|
|
|
+ const dataUrl = canvas.toDataURL(urlData.type, midQuality);
|
|
|
+ let result = that
|
|
|
+ .uploadFilePromise(dataUrl)
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve(
|
|
|
+ result)
|
|
|
+ }, 1000)
|
|
|
+
|
|
|
+ } else if (fileSizeKB > targetSizeKB) {
|
|
|
+ // 如果文件大小太大,降低质量,继续二分查找
|
|
|
+ binarySearch(min, midQuality);
|
|
|
+ } else {
|
|
|
+ // 如果文件大小太小,增加质量,继续二分查找
|
|
|
+ binarySearch(midQuality, max);
|
|
|
+ }
|
|
|
+ }, urlData.type, midQuality);
|
|
|
+ };
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '图片压缩失败',
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 开始二分查找
|
|
|
+ binarySearch(minQuality, maxQuality);
|
|
|
})
|
|
|
- result1.url = window.URL.createObjectURL(result)
|
|
|
- return result1
|
|
|
},
|
|
|
// 新增图片
|
|
|
async afterRead(event) {
|
|
|
uni.showLoading({
|
|
|
- title:"上传中"
|
|
|
+ title: "上传中"
|
|
|
})
|
|
|
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
|
|
|
let lists = [].concat(event.file)
|
|
@@ -240,48 +242,47 @@
|
|
|
})
|
|
|
})
|
|
|
for (let i = 0; i < lists.length; i++) {
|
|
|
- let result =""
|
|
|
- if (isImageFormat(lists[i].name) && lists[i].size > (200 * 1024)) {
|
|
|
- result = await this.compressH5(lists[i]);
|
|
|
- }else {
|
|
|
- result = await this.uploadFilePromise(lists[i])
|
|
|
- }
|
|
|
- let item = this.fileLists[fileListLen]
|
|
|
-
|
|
|
- this.fileLists.splice(fileListLen, 1, Object.assign(item, {
|
|
|
- status: 'success',
|
|
|
- message: '',
|
|
|
- url: result
|
|
|
- }))
|
|
|
- fileListLen++
|
|
|
- if (isImageFormat(item.url)) {
|
|
|
+ let result = ""
|
|
|
+ if (isImageFormat(lists[i].name)) {
|
|
|
+ if (lists[i].size > (200 * 1024)) {
|
|
|
+ result = await this.compressH5(lists[i], 150);
|
|
|
+ } else {
|
|
|
+ result = await this.uploadFilePromise(lists[i].url)
|
|
|
+ }
|
|
|
let item1 = {
|
|
|
url: BASE_URL + result
|
|
|
}
|
|
|
this.imgList.push(item1)
|
|
|
+
|
|
|
} else {
|
|
|
- const fileName = item.url.split(/[/\\=]/).pop();
|
|
|
+ result = await this.uploadFilePromise(lists[i].url)
|
|
|
+ const fileName = result.split(/[/\\=]/).pop();
|
|
|
let a = {
|
|
|
name: fileName,
|
|
|
- url: item.url
|
|
|
+ url: BASE_URL + result
|
|
|
}
|
|
|
this.fileList.push(a)
|
|
|
}
|
|
|
+ let item = this.fileLists[fileListLen]
|
|
|
+ this.fileLists.splice(fileListLen, 1, Object.assign(item, {
|
|
|
+ status: 'success',
|
|
|
+ message: '',
|
|
|
+ url: result
|
|
|
+ }))
|
|
|
+ fileListLen++
|
|
|
}
|
|
|
uni.hideLoading()
|
|
|
},
|
|
|
async uploadFilePromise(param) {
|
|
|
-
|
|
|
return new Promise((resolve, reject) => {
|
|
|
-
|
|
|
+
|
|
|
let a = uni.uploadFile({
|
|
|
url: this.BASE_URL + '/gwfile/upload?uploadPath=filtransmit',
|
|
|
- filePath: param.url,
|
|
|
+ filePath: param,
|
|
|
name: 'file',
|
|
|
header: {
|
|
|
"token": $auth.getUserToken()
|
|
|
},
|
|
|
- formData: param,
|
|
|
success: (res) => {
|
|
|
setTimeout(() => {
|
|
|
resolve(res.data)
|
|
@@ -304,29 +305,37 @@
|
|
|
files.push(item.url)
|
|
|
})
|
|
|
this.inputForm.attachedDocumentId = files.join(",");
|
|
|
- this.inputForm.writtenTime = this.inputForm.writtenTime+" 00:00:00";
|
|
|
- this.inputForm.receivingTime = this.inputForm.receivingTime+" 00:00:00";
|
|
|
- // this.$refs['inputForm'].validate((valid) => {
|
|
|
- // if (valid) {
|
|
|
- gwCirculationCard2Service.save(this.inputForm).then((data) => {
|
|
|
+ this.inputForm.writtenTime = this.inputForm.writtenTime + " 00:00:00";
|
|
|
+ this.inputForm.receivingTime = this.inputForm.receivingTime + " 00:00:00";
|
|
|
+ this.inputForm.cardNum = this.cardNum
|
|
|
+ this.$refs.inputForm.validate().then(valid => {
|
|
|
+ console.log("valid", valid);
|
|
|
+ if (valid) {
|
|
|
+ gwCirculationCard2Service.save(this.inputForm).then((data) => {
|
|
|
|
|
|
- let param = {
|
|
|
- type: 'success',
|
|
|
- message: data,
|
|
|
- iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png',
|
|
|
- url: "/pages/index/index"
|
|
|
- }
|
|
|
- this.showToast(param);
|
|
|
- }).catch(() => {
|
|
|
- let param = {
|
|
|
- type: 'error',
|
|
|
- message: data,
|
|
|
- iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png',
|
|
|
+ let param = {
|
|
|
+ type: 'success',
|
|
|
+ message: data,
|
|
|
+ iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png',
|
|
|
+ url: "/pages/index/index"
|
|
|
+ }
|
|
|
+ this.showToast(param);
|
|
|
+ }).catch(() => {
|
|
|
+ let param = {
|
|
|
+ type: 'error',
|
|
|
+ message: data,
|
|
|
+ iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png',
|
|
|
+ }
|
|
|
+ this.showToast(param);
|
|
|
+ })
|
|
|
}
|
|
|
- this.showToast(param);
|
|
|
+ }).catch(e => {
|
|
|
+ this.inputForm.cardNum = "[" + this.inputForm.yearNum + "]" + this.cardNum + "号"
|
|
|
+ this.inputForm.writtenTime = moment().format('YYYY-MM-DD');
|
|
|
+ this.inputForm.receivingTime = moment().format('YYYY-MM-DD');
|
|
|
+ this.loading = false
|
|
|
})
|
|
|
- // }
|
|
|
- // })
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -334,13 +343,19 @@
|
|
|
</script>
|
|
|
|
|
|
<style>
|
|
|
+ .warp {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
.default_title {
|
|
|
padding-top: 0px;
|
|
|
}
|
|
|
|
|
|
.main_info {
|
|
|
margin-top: 15px;
|
|
|
- /* height: 80vh; */
|
|
|
}
|
|
|
|
|
|
.submit_btn {
|