|
@@ -0,0 +1,527 @@
|
|
|
+<template>
|
|
|
+ <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--input readonly v-model="inputForm.yearNum" placeholder="输入年度" border="none"></u--input>
|
|
|
+ </u-form-item>
|
|
|
+ <u-form-item label="卡号" borderBottom prop="cardNum">
|
|
|
+ <u--input readonly v-model="inputForm.cardNum" placeholder="输入卡号" border="none"></u--input>
|
|
|
+ </u-form-item>
|
|
|
+ </u--form>
|
|
|
+ </view>
|
|
|
+ <view class="bg-white margin-top main_info">
|
|
|
+ <u--form :model="inputForm" :rules="rules" labelWidth="130px" class="u-form default_title"
|
|
|
+ labelPosition="left" ref="inputForm">
|
|
|
+ <u-form-item required label="文件名称" borderBottom prop="name">
|
|
|
+ <u--input v-model="inputForm.name" placeholder="请输入文件名称" border="none"></u--input>
|
|
|
+ </u-form-item>
|
|
|
+ <u-form-item label="拟稿人" borderBottom prop="authorPerson">
|
|
|
+ <u--input readonly v-model="$auth.getUserInfo().name" border="none"></u--input>
|
|
|
+ </u-form-item>
|
|
|
+ <u-form-item required label="校对人" borderBottom prop="proofreader">
|
|
|
+ <office-user-select v-model="inputForm.proofreader" placeholder="请选择校对人" title="校对人"
|
|
|
+ myOffice types="3,6"></office-user-select>
|
|
|
+ </u-form-item>
|
|
|
+ <u-form-item label="印数" borderBottom prop="printNum">
|
|
|
+ <u-number-box integer v-model="inputForm.printNum"></u-number-box>
|
|
|
+ </u-form-item>
|
|
|
+ <u-form-item label="是否公开" borderBottom prop="open">
|
|
|
+ <u-radio-group v-model="inputForm.open">
|
|
|
+ <u-radio style="margin-right: 20px;" label="是" name="1"></u-radio>
|
|
|
+ <u-radio label="否" name="0"></u-radio>
|
|
|
+ </u-radio-group>
|
|
|
+ </u-form-item>
|
|
|
+ <u-form-item label="备注" borderBottom prop="remark">
|
|
|
+ <u--input v-model="inputForm.remark" placeholder="请输入备注" border="none"></u--input>
|
|
|
+ </u-form-item>
|
|
|
+ <u-form-item label="文件附件" prop="attachment" labelPosition="top">
|
|
|
+ <lsj-upload ref="lsjUpload" childId="upload1" width="250rpx" height="200rpx" :option="option"
|
|
|
+ :debug="false" :instantly="false" @uploadEnd="onuploadEnd" @change="afterRead">
|
|
|
+ <view class="addfile flex">
|
|
|
+ <u-icon size="20" bold name="plus"></u-icon>
|
|
|
+ </view>
|
|
|
+ </lsj-upload>
|
|
|
+ <!-- #ifdef H5 -->
|
|
|
+ <view class="takephoto addfile flex" @click="takePhoto"> <u-icon size="20" bold
|
|
|
+ name="camera"></u-icon>
|
|
|
+ </view>
|
|
|
+ <!-- #endif -->
|
|
|
+ </u-form-item>
|
|
|
+ <view class="text-danger" style="font-size: 12px!important;">请确保上传图片内容清晰可见,所有涉密敏感信息不得上传</view>
|
|
|
+ <view class="other_info">
|
|
|
+ <view class="other_pdf">
|
|
|
+ <u-cell-group>
|
|
|
+ <u-cell v-for="item in fileList">
|
|
|
+ <view slot="title">
|
|
|
+ <u--text :lines="1" :text="item.name"></u--text>
|
|
|
+ </view>
|
|
|
+ <u-icon slot="value" size="28" name="trash-fill" @click="deleteFile(item)"></u-icon>
|
|
|
+ </u-cell>
|
|
|
+ </u-cell-group>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <u-upload :fileList="imgList" @delete="deletePic" multiple :maxCount="imgList.length"
|
|
|
+ :previewFullImage="true"></u-upload>
|
|
|
+
|
|
|
+ <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>
|
|
|
+ </view>
|
|
|
+ </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>
|
|
|
+
|
|
|
+<script>
|
|
|
+ import {
|
|
|
+ isImageFormat
|
|
|
+ } from "@/common/util.js"
|
|
|
+ import BASE_URL from '@/config.js'
|
|
|
+ import moment from "moment"
|
|
|
+ import * as $auth from "@/common/auth.js"
|
|
|
+ import userService from "@/api/sys/userService"
|
|
|
+ import fileService from '@/api/file/fileService.js'
|
|
|
+ import yzCirculationCardService from '@/api/commonseal/yzCirculationCardService.js'
|
|
|
+ export default {
|
|
|
+ mounted() {
|
|
|
+ userService.list({
|
|
|
+ current: 1,
|
|
|
+ size: 10000
|
|
|
+ }).then((res) => {
|
|
|
+ this.userList = res.records
|
|
|
+ }).catch((e) => {
|
|
|
+ throw e
|
|
|
+ })
|
|
|
+ yzCirculationCardService.getCardNum().then(data => {
|
|
|
+ this.inputForm.authorPerson = $auth.getUserInfo().id
|
|
|
+ const currentYear = new Date().getFullYear();
|
|
|
+ this.inputForm.yearNum = currentYear
|
|
|
+ this.cardNum = data
|
|
|
+ this.inputForm.cardNum = "[" + currentYear + "]" + data + "号"
|
|
|
+ })
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ imgsrc: {},
|
|
|
+ loading: false,
|
|
|
+ isreceive: false,
|
|
|
+ iswrite: false,
|
|
|
+ fileLists: [],
|
|
|
+ fileList: [],
|
|
|
+ files: [],
|
|
|
+ imgList: [],
|
|
|
+ userList: [],
|
|
|
+ cardNum: "",
|
|
|
+ inputForm: {
|
|
|
+ id: '',
|
|
|
+ name: '',
|
|
|
+ authorPerson: '',
|
|
|
+ proofreader: '',
|
|
|
+ open: '1',
|
|
|
+ printNum: '1',
|
|
|
+ state: '1',
|
|
|
+ cardNum: '',
|
|
|
+ yearNum: '',
|
|
|
+ attachment: '',
|
|
|
+ remark: '',
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ name: [{
|
|
|
+ required: true,
|
|
|
+ message: '请输入文件名称',
|
|
|
+ trigger: ['blur', 'change']
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ // 上传接口参数
|
|
|
+ option: {
|
|
|
+ url: BASE_URL + '/gwfile/upload?uploadPath=commonseal',
|
|
|
+ name: 'file',
|
|
|
+ header: {
|
|
|
+ "token": $auth.getUserToken()
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+
|
|
|
+ showToast(params) {
|
|
|
+ this.loading = false
|
|
|
+ this.$refs.uToast.show({
|
|
|
+ ...params,
|
|
|
+ complete() {
|
|
|
+ params.url && uni.redirectTo({
|
|
|
+ url: params.url
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 删除文件
|
|
|
+ deleteFile(item) {
|
|
|
+ let that = this
|
|
|
+ that.fileList = that.fileList.filter(i => !(i.url == item.url))
|
|
|
+ that.fileLists = that.fileLists.filter(i => !(i.url == item.url))
|
|
|
+
|
|
|
+ },
|
|
|
+ // 删除图片
|
|
|
+ deletePic(event) {
|
|
|
+ let that = this
|
|
|
+ this.imgList = this.imgList.filter(item => item.name != event.file.name)
|
|
|
+ that.fileLists = that.fileLists.filter(i => !(i.name == event.file.name))
|
|
|
+ },
|
|
|
+ // 图片压缩
|
|
|
+ compressH5(urlData, targetSizeKB, initialQuality = 1.0) {
|
|
|
+ const maxQuality = 1.0;
|
|
|
+ const minQuality = 0.0;
|
|
|
+ const tolerance = 0.01; // 根据需要调整公差
|
|
|
+ if (!urlData.url) {
|
|
|
+ this.$set(urlData, "url", urlData.path)
|
|
|
+ }
|
|
|
+ let that = this
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let binarySearch = (min, max) => {
|
|
|
+ const midQuality = (min + max) / 2;
|
|
|
+ uni.getImageInfo({
|
|
|
+ src: urlData.url,
|
|
|
+ success(res) {
|
|
|
+ const reader = new FileReader();
|
|
|
+ let img = new Image()
|
|
|
+ img.src = res.path
|
|
|
+ img.onload = function() {
|
|
|
+ const canvas = document.createElement('canvas');
|
|
|
+ const ctx = canvas.getContext('2d');
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ // 当前质量足够接近目标大小,使用当前质量解析
|
|
|
+ reader.readAsDataURL(blob);
|
|
|
+ reader.onload = () => {
|
|
|
+ let result = that
|
|
|
+ .uploadFilePromise(reader
|
|
|
+ .result)
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve(result)
|
|
|
+ }, 300)
|
|
|
+ }
|
|
|
+ } else if (fileSizeKB >
|
|
|
+ targetSizeKB) {
|
|
|
+ // 如果文件大小太大,降低质量,继续二分查找
|
|
|
+ binarySearch(min, midQuality);
|
|
|
+ } else {
|
|
|
+ // 如果文件大小太小,增加质量,继续二分查找
|
|
|
+ binarySearch(midQuality, max);
|
|
|
+ }
|
|
|
+ }, urlData.type, midQuality);
|
|
|
+ };
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 开始二分查找
|
|
|
+ binarySearch(minQuality, maxQuality);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 拍照
|
|
|
+ takePhoto() {
|
|
|
+ let that = this
|
|
|
+ // 调用uniapp的chooseImage API 选择图片
|
|
|
+ uni.chooseImage({
|
|
|
+ count: 1, // 默认9, 设置图片的数量
|
|
|
+ sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
|
+ sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
|
+ success: (chooseImageRes) => {
|
|
|
+ uni.showLoading({
|
|
|
+ title: "上传中"
|
|
|
+ })
|
|
|
+ const tempFilePaths = chooseImageRes.tempFiles[0];
|
|
|
+ // 成功选择图片后进行压缩处理
|
|
|
+ that.compressH5(tempFilePaths, 150).then(result => {
|
|
|
+ const fileName = result.split(/[/\\=]/).pop();
|
|
|
+ let item1 = {
|
|
|
+ name: fileName,
|
|
|
+ url: BASE_URL + result
|
|
|
+ }
|
|
|
+ let item = {
|
|
|
+ name: fileName,
|
|
|
+ path: result,
|
|
|
+
|
|
|
+ }
|
|
|
+ that.fileLists.push(item)
|
|
|
+ that.imgList.push(item1)
|
|
|
+ uni.hideLoading()
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ fail: (error) => {
|
|
|
+ uni.hideLoading()
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 拍照上传
|
|
|
+ async uploadFilePromise(param) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let a = uni.uploadFile({
|
|
|
+ url: this.BASE_URL + '/gwfile/upload?uploadPath=commonseal',
|
|
|
+ filePath: param,
|
|
|
+ name: 'file',
|
|
|
+ header: {
|
|
|
+ "token": $auth.getUserToken()
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve(res.data)
|
|
|
+ }, 300)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 新增图片
|
|
|
+ afterRead(files) {
|
|
|
+ uni.showLoading({
|
|
|
+ title: "上传中"
|
|
|
+ })
|
|
|
+ let lists = [...files.values()]
|
|
|
+ this.files = files
|
|
|
+ for (let i = 0; i < lists.length; i++) {
|
|
|
+ if (lists[i].type == 'success') continue;
|
|
|
+ if (isImageFormat(lists[i].name) && lists[i].size > 200 * 1024) {
|
|
|
+ this.compressAPP(lists[i], 150).then(res => {
|
|
|
+ this.files.get(lists[i].name).file = res
|
|
|
+ this.upload(lists[i].name)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.upload(lists[i].name)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ // app图片压缩
|
|
|
+ compressAPP(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 binarySearch = (min, max) => {
|
|
|
+ const midQuality = (min + max) / 2;
|
|
|
+ uni.getImageInfo({
|
|
|
+ src: urlData.path,
|
|
|
+ success: function(res) {
|
|
|
+ let img = new Image()
|
|
|
+ img.src = res.path
|
|
|
+ img.onload = function() {
|
|
|
+ const canvas = document.createElement('canvas');
|
|
|
+ const ctx = canvas.getContext('2d');
|
|
|
+
|
|
|
+ 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 file = new File([blob], urlData
|
|
|
+ .name, {
|
|
|
+ type: blob.type,
|
|
|
+ lastModified: new Date()
|
|
|
+ .getTime(), // 使用当前时间作为最后修改时间
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve(file)
|
|
|
+ }, 300)
|
|
|
+ } else if (fileSizeKB >
|
|
|
+ targetSizeKB) {
|
|
|
+ // 如果文件大小太大,降低质量,继续二分查找
|
|
|
+ binarySearch(min, midQuality);
|
|
|
+ } else {
|
|
|
+ // 如果文件大小太小,增加质量,继续二分查找
|
|
|
+ binarySearch(midQuality, max);
|
|
|
+ }
|
|
|
+ }, urlData.file.type, midQuality);
|
|
|
+ };
|
|
|
+ },
|
|
|
+ fail: function(err) {
|
|
|
+ resolve(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ // 开始二分查找
|
|
|
+ binarySearch(minQuality, maxQuality);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // APP手动上传
|
|
|
+ upload(name) {
|
|
|
+ // name=指定文件名,不指定则上传所有type等于waiting和fail的文件
|
|
|
+ this.$refs['lsjUpload'].upload(name);
|
|
|
+ },
|
|
|
+ onuploadEnd(item) {
|
|
|
+ console.log(`${item.name}已上传结束,上传状态=${item.type}`);
|
|
|
+
|
|
|
+ // 更新当前窗口状态变化的文件
|
|
|
+ this.files.set(item.name, item);
|
|
|
+ let file = {
|
|
|
+ name: item.name,
|
|
|
+ path: item.responseText
|
|
|
+ }
|
|
|
+ this.fileLists.push(file)
|
|
|
+
|
|
|
+ const fileName = item.name.split(/[/\\=]/).pop();
|
|
|
+ if (isImageFormat(item.name)) {
|
|
|
+ let item1 = {
|
|
|
+ name: fileName,
|
|
|
+ url: this.BASE_URL + item.responseText
|
|
|
+ }
|
|
|
+ this.imgList.push(item1)
|
|
|
+ } else {
|
|
|
+ let a = {
|
|
|
+ name: fileName,
|
|
|
+ url: this.BASE_URL + item.responseText
|
|
|
+ }
|
|
|
+ this.fileList.push(a)
|
|
|
+ }
|
|
|
+ uni.hideLoading()
|
|
|
+ // 微信小程序Map对象for循环不显示,所以转成普通数组,
|
|
|
+ // 如果你用不惯Map对象,也可以像这样转普通数组,组件使用Map主要是避免反复文件去重操作
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
+ this.wxFiles = [...this.files.values()];
|
|
|
+ // #endif
|
|
|
+
|
|
|
+ // 强制更新视图
|
|
|
+ this.$forceUpdate();
|
|
|
+
|
|
|
+ // ---可删除--演示判断是否所有文件均已上传成功
|
|
|
+ let isAll = [...this.files.values()].find(item => item.type !== 'success');
|
|
|
+ if (!isAll) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ console.log(isAll.name + '待上传');
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ // 下载文件
|
|
|
+ download(param) {
|
|
|
+ fileService.download(param).then(data)
|
|
|
+ },
|
|
|
+ // 表单提交
|
|
|
+ formSubmit() {
|
|
|
+ this.loading = true
|
|
|
+ let auditForm = Object.assign({}, this.inputForm);
|
|
|
+ let files = []
|
|
|
+ this.fileLists.forEach(item => {
|
|
|
+ files.push(item.path)
|
|
|
+ })
|
|
|
+ auditForm.attachment = files.join(",");
|
|
|
+ auditForm.cardNum = this.cardNum
|
|
|
+ this.$refs.inputForm.validate().then(valid => {
|
|
|
+ if (valid) {
|
|
|
+ yzCirculationCardService.save(auditForm).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',
|
|
|
+ }
|
|
|
+ this.showToast(param);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }).catch(e => {
|
|
|
+ this.loading = false
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+ .warp {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .default_title {
|
|
|
+ padding-top: 0px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .main_info {
|
|
|
+ margin-top: 15px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .u-form-item__body__right__message span {
|
|
|
+ font-size: 12px !important;
|
|
|
+ }
|
|
|
+
|
|
|
+ .submit_btn {
|
|
|
+ background-color: #fefefe;
|
|
|
+ margin-top: 20px;
|
|
|
+ box-shadow: none;
|
|
|
+ margin-bottom: 20px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .submit_btn button {
|
|
|
+ height: 40px;
|
|
|
+ width: 80%;
|
|
|
+ border-radius: 30px;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ .addfile {
|
|
|
+ width: 80px;
|
|
|
+ height: 80px;
|
|
|
+ background-color: #eee;
|
|
|
+ padding-left: 30%;
|
|
|
+ /* padding-left: 18%; */
|
|
|
+ margin: 10px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .takephoto {
|
|
|
+ padding-left: 9%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .other_info {
|
|
|
+ width: 100%;
|
|
|
+ }
|
|
|
+</style>
|