|
|
@@ -11,23 +11,39 @@
|
|
|
<view class="page-form">
|
|
|
<!-- 选择打印机--获取打印参数--上传打印 -->
|
|
|
<wd-form ref="form" :model="formData">
|
|
|
- <!-- :rules=rules -->
|
|
|
<wd-cell-group custom-class="form-group" border>
|
|
|
- <wd-cell :title="`上传${accept == 'image' ? '图片' : '文件'}`"
|
|
|
+ <wd-cell title="上传文件"
|
|
|
title-width="100px"
|
|
|
required
|
|
|
- prop="fileList">
|
|
|
- <!-- :rules="[{ required: true, message: '请上传图片', validator: validateFileList }]" -->
|
|
|
- <wd-upload
|
|
|
- ref="uploader"
|
|
|
- :accept="accept"
|
|
|
- :auto-upload="false"
|
|
|
- :limit="1"
|
|
|
- :file-list="fileList"
|
|
|
- :before-upload="beforeUpload"
|
|
|
- :upload-method="handleUpload"
|
|
|
- @change="handleFileChange"
|
|
|
- ></wd-upload>
|
|
|
+ prop="fileList"
|
|
|
+ custom-class="my-cell">
|
|
|
+ <view class="file-list">
|
|
|
+ <view v-for="(item, index) of fileList"
|
|
|
+ :key="item.filePath"
|
|
|
+ class="file-item"
|
|
|
+ @click="previewFile(item.filePath)">
|
|
|
+ <view class="item-icon">
|
|
|
+ <wd-img
|
|
|
+ :src="getFileIcon(item.name)"
|
|
|
+ :width="20"
|
|
|
+ :height="20"
|
|
|
+ mode="aspectFit"
|
|
|
+ ></wd-img>
|
|
|
+ </view>
|
|
|
+ <view class="item-name">{{ item.name }}</view>
|
|
|
+ <view class="item-del" @click.stop="removeFile(index)">
|
|
|
+ <wd-img
|
|
|
+ :src="delSrc"
|
|
|
+ :width="20"
|
|
|
+ :height="20"
|
|
|
+ mode="aspectFit"
|
|
|
+ ></wd-img>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 选择文件: 支持多选多个 (系统文件另外传入) -->
|
|
|
+ <wd-button v-if="accept != 'all'" size="small" @click="selectFile()">选择文件</wd-button>
|
|
|
+ </view>
|
|
|
</wd-cell>
|
|
|
|
|
|
<wd-select-picker
|
|
|
@@ -37,7 +53,7 @@
|
|
|
type="radio"
|
|
|
:columns="printerList"
|
|
|
value-key="id"
|
|
|
- label-key="name"
|
|
|
+ label-key="showName"
|
|
|
:max="1"
|
|
|
:show-confirm="false"
|
|
|
filterable
|
|
|
@@ -88,14 +104,8 @@
|
|
|
title-width="100px"
|
|
|
custom-class="my-cell"
|
|
|
:prop="option.key">
|
|
|
- <!-- :rules="[{ required: true, message: `请选择${option.text}` }]" -->
|
|
|
-
|
|
|
- <!-- 滑块 -->
|
|
|
- <!-- <wd-slider v-model="formData[option.key]"
|
|
|
- :min="option.min"
|
|
|
- :max="option.max" /> -->
|
|
|
-
|
|
|
- <!-- 输入框: 从 xx 到 xx (TODO: 需增加 min max 控制) -->
|
|
|
+ <!-- TODO: 需增加 option.min option.max 控制; 默认全部 -->
|
|
|
+ <!-- 输入框: 从 xx 到 xx -->
|
|
|
<view style="text-align: left">
|
|
|
<view class="inline-txt" style="margin-left: 0">从</view>
|
|
|
<wd-input
|
|
|
@@ -133,73 +143,301 @@
|
|
|
<wd-button type="primary" size="large" block @click="handleSubmit()">确认打印</wd-button>
|
|
|
</view>
|
|
|
</wd-form>
|
|
|
+
|
|
|
+ <!-- 当前打印任务 及 实时状态 -->
|
|
|
+ <!-- 连接SSE: /print/see/connection -->
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
import { useToast, useMessage } from 'wot-design-uni'
|
|
|
-import { getUserHubPrints, getUserHubAttr, printFile } from '@/service/api'
|
|
|
-import { isArray } from 'wot-design-uni/components/common/util'
|
|
|
-import FormData from '@/utils/formData'
|
|
|
-import { getEnvBaseUrl } from '@/utils'
|
|
|
+import { getUserHubPrints, getUserHubAttr, getInvoiceInfo, getInvoiceBatch } from '@/service/api'
|
|
|
+import { getEnvBaseUrl, redirectToUpload, reLaunchToHome } from '@/utils'
|
|
|
|
|
|
const baseUrl = getEnvBaseUrl()
|
|
|
const toast = useToast()
|
|
|
const message = useMessage()
|
|
|
+// 系统文件--all, 聊天文件--msg, 相册--image, 发票--invoice
|
|
|
const accept = ref("all")
|
|
|
-const uploader = ref()
|
|
|
const fileList = ref([])
|
|
|
+// 测试发票
|
|
|
+// const fileList = ref([
|
|
|
+// {name: "测试发票.pdf", filePath: "https://pay.weixin.qq.com/invoicing/invoicepdf/getpdf?type=invoice&card_id=pmB7twzboHW_C66OLCIqz4VYkpjw&wx_invoice_token=FCFimpsJEytCHNpnEzqafLRmT_5NV5Mk0evaCTOrJeB3J_EI2Wvn0jSQAJnMrd0xVG8vxpcfhpeNOSn5XGEYfg.%3D"}
|
|
|
+// ])
|
|
|
const form = ref()
|
|
|
const formData: any = ref({
|
|
|
printer: "",
|
|
|
})
|
|
|
const printerList: any = ref([])
|
|
|
const printerOptions: any = ref([])
|
|
|
-const hasFile = ref(false)
|
|
|
+const allowType = ['txt', 'pdf', 'doc', 'docx', 'xlsx', 'xls', 'ppt', 'pptx', 'gif', 'png', 'jpg', 'jpeg', 'webp']
|
|
|
+const maxSize = 10 * 1024 * 1024
|
|
|
|
|
|
-// TODO: 优化上传文件校验
|
|
|
-// const rules = {
|
|
|
-// fileList: [{ required: true, message: '请上传图片', validator: validateFileList }],
|
|
|
-// }
|
|
|
+// 文件类型
|
|
|
+const imageSrc = '/static/images/image.png'
|
|
|
+const docSrc = '/static/images/doc.png'
|
|
|
+const xlsSrc = '/static/images/xls.png'
|
|
|
+const pptSrc = '/static/images/ppt.png'
|
|
|
+const pdfSrc = '/static/images/pdf.png'
|
|
|
+const txtSrc = '/static/images/txt.png'
|
|
|
+const otherSrc = '/static/images/other.png'
|
|
|
+const delSrc = '/static/images/deleteIcon.png'
|
|
|
+// 文件类型图片匹配
|
|
|
+const srcMap = {
|
|
|
+ 'doc': docSrc,
|
|
|
+ 'docx': docSrc,
|
|
|
+ 'xls': xlsSrc,
|
|
|
+ 'xlsx': xlsSrc,
|
|
|
+ 'ppt': pptSrc,
|
|
|
+ 'pptx': pptSrc,
|
|
|
+ 'png': imageSrc,
|
|
|
+ 'jpg': imageSrc,
|
|
|
+ 'jpeg': imageSrc,
|
|
|
+ 'gif': imageSrc,
|
|
|
+ 'webp': imageSrc,
|
|
|
+ 'txt': txtSrc,
|
|
|
+ 'pdf': pdfSrc,
|
|
|
+}
|
|
|
+
|
|
|
+// SSE连接
|
|
|
|
|
|
defineOptions({
|
|
|
name: 'Print',
|
|
|
})
|
|
|
|
|
|
-function beforeUpload({ files, resolve }) {
|
|
|
- // 当前允许格式
|
|
|
- const allowType = ['txt', 'pdf', 'doc', 'docx', 'xlsx', 'xls', 'ppt', 'pptx', 'gif', 'png', 'jpg', 'jpeg', 'webp']
|
|
|
- // 当前允许大小: 10M
|
|
|
- const maxSize = 10 * 1024 * 1024
|
|
|
- if (files.length && files[0].path) {
|
|
|
- const lastIndex = files[0].path.lastIndexOf('.')
|
|
|
- if (lastIndex != -1) {
|
|
|
- const fileType = files[0].path.substring(lastIndex + 1)
|
|
|
- if (allowType.includes(fileType)) {
|
|
|
- if (files[0].size <= maxSize) {
|
|
|
- hasFile.value = true
|
|
|
- resolve(true)
|
|
|
- } else {
|
|
|
- toast.warning("上传文件最大为10M")
|
|
|
- resolve(false)
|
|
|
+// 获取打印机
|
|
|
+function getPrinterList() {
|
|
|
+ let params = { id: "" }
|
|
|
+ getUserHubPrints(params)
|
|
|
+ .then((res: any) => {
|
|
|
+ if (res.code === 0 && res.body) {
|
|
|
+ printerList.value = res.body || []
|
|
|
+ printerList.value.forEach(item => {
|
|
|
+ item.showName = `${item.name} (${item.userHubName})`
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((e) => {})
|
|
|
+}
|
|
|
+
|
|
|
+// 处理更换打印机
|
|
|
+function handlePrinterChange(item: any) {
|
|
|
+ let obj = printerList.value.find(i => i.id == item.value) || {}
|
|
|
+ let params = {
|
|
|
+ id: obj.userHubId,
|
|
|
+ printer: obj.name,
|
|
|
+ }
|
|
|
+ getUserHubAttr(params)
|
|
|
+ .then((res: any) => {
|
|
|
+ if (res.code === 0 && res.body) {
|
|
|
+ printerOptions.value = res.body || []
|
|
|
+ let _formData = {
|
|
|
+ printer: item.value,
|
|
|
+ userHubId: obj.userHubId,
|
|
|
+ printerName: obj.name,
|
|
|
+ }
|
|
|
+ if (printerOptions.value.length) {
|
|
|
+ printerOptions.value.forEach(option => {
|
|
|
+ switch(option.type) {
|
|
|
+ case "rang":
|
|
|
+ _formData[option.key] = option.def ? option.def.split(',') : [option.min, '']
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ _formData[option.key] = option.def
|
|
|
+ }
|
|
|
+ });
|
|
|
+ formData.value = _formData
|
|
|
}
|
|
|
- } else {
|
|
|
- toast.warning(`仅支持 ${allowType.join(",")} 格式的文件`)
|
|
|
- resolve(false)
|
|
|
}
|
|
|
- } else {
|
|
|
- toast.warning(`仅支持 ${allowType.join(",")} 格式的文件`)
|
|
|
- resolve(false)
|
|
|
- }
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ })
|
|
|
+ .finally(() => {})
|
|
|
+}
|
|
|
+
|
|
|
+// 获取文件格式
|
|
|
+function getFileType(fileName) {
|
|
|
+ let type = ""
|
|
|
+ const lastIndex = fileName.lastIndexOf('.')
|
|
|
+ if (lastIndex != -1) {
|
|
|
+ type = fileName.substring(lastIndex + 1)
|
|
|
}
|
|
|
+ return type
|
|
|
}
|
|
|
|
|
|
-function handleFileChange(data) {
|
|
|
- fileList.value = data.fileList
|
|
|
- hasFile.value = fileList.value.length > 0
|
|
|
+// 获取文件图标
|
|
|
+function getFileIcon(fileName) {
|
|
|
+ return srcMap[getFileType(fileName)] || otherSrc
|
|
|
}
|
|
|
|
|
|
-function handleUpload(file, data, options) {
|
|
|
+// 处理选择文件
|
|
|
+function selectFile() {
|
|
|
+ switch(accept.value) {
|
|
|
+ case "msg":
|
|
|
+ uni.chooseMessageFile({
|
|
|
+ count: 1,
|
|
|
+ type: "all",
|
|
|
+ success (res) {
|
|
|
+ console.log('chooseMessageFile res: ', res);
|
|
|
+ if (res.errMsg == "chooseMessageFile:ok") {
|
|
|
+ let failList = []
|
|
|
+ res.tempFiles.forEach(item => {
|
|
|
+ if (item.size > maxSize || !allowType.includes(getFileType(item.name))) {
|
|
|
+ failList.push(item)
|
|
|
+ } else {
|
|
|
+ fileList.value.push({
|
|
|
+ name: item.name,
|
|
|
+ filePath: item.path,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (failList.length > 0) toast.warning(`文件大小限制为10MB, 文件格式仅支持 ${allowType.join('、')}, 所选文件有 ${failList.length} 格式不符合`)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail () {
|
|
|
+ toast.warning("选择微信文件失败, 请重试")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ break;
|
|
|
+ case "image":
|
|
|
+ uni.chooseImage({
|
|
|
+ count: 1,
|
|
|
+ sourceType: ['album', 'camera'],
|
|
|
+ sizeType: ['original', 'compressed'],
|
|
|
+ extension: ['png', 'jpg', 'jpeg', 'gif', 'webp'],
|
|
|
+ success (res) {
|
|
|
+ console.log('chooseImage res: ', res);
|
|
|
+ if (res.errMsg == "chooseImage:ok") {
|
|
|
+ let failList = []
|
|
|
+ res.tempFiles.forEach(item => {
|
|
|
+ if (item.size > maxSize) {
|
|
|
+ failList.push(item)
|
|
|
+ } else {
|
|
|
+ fileList.value.push({
|
|
|
+ // name: item.path.substring(item.path.lastIndexOf("/") + 1),
|
|
|
+ name: `图片-${new Date().getTime()}.${getFileType(item.path)}`,
|
|
|
+ filePath: item.path,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (failList.length > 0) toast.warning(`文件大小限制为10MB, 所选文件有 ${failList.length} 格式不符合`)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail () {
|
|
|
+ toast.warning("选择相册图片失败, 请重试")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ break;
|
|
|
+ case "invoice":
|
|
|
+ uni.chooseInvoice({
|
|
|
+ success (res) {
|
|
|
+ if (res.errMsg == "chooseInvoice:ok") {
|
|
|
+ let list = JSON.parse(res.invoiceInfo)
|
|
|
+ if (list && list.length > 0) {
|
|
|
+ let params = {
|
|
|
+ cardId: list.map(i => i.card_id).join(","),
|
|
|
+ encryptCode: list.map(i => i.encrypt_code).join(","),
|
|
|
+ }
|
|
|
+ getInvoiceBatch(params).then(res => {
|
|
|
+ if (res.code == 0 && res.body) {
|
|
|
+ console.log('InvoiceBatch res.body: ', res.body);
|
|
|
+ // 遍历下载pdf 存储在 fileList 打印
|
|
|
+ res.body.forEach(item => {
|
|
|
+ downloadFile(`微信发票-${item.payee}.png`, item.userInfo.pdfUrl)
|
|
|
+
|
|
|
+ // 直接下会有白名单问题
|
|
|
+ // fileList.value.push({
|
|
|
+ // name: `微信发票-${item.payee}.pdf`,
|
|
|
+ // filePath: item.userInfo.pdfUrl
|
|
|
+ // })
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail () {
|
|
|
+ toast.warning("选择微信发票失败, 请重试")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 下载文件(用于处理发票)
|
|
|
+function downloadFile(fileName, fileUrl) {
|
|
|
+ console.log('fileUrl: ', fileUrl);
|
|
|
+ uni.downloadFile({
|
|
|
+ url: fileUrl,
|
|
|
+ header: {
|
|
|
+ 'Content-Type': "application/png"
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ console.log('download res: ', res);
|
|
|
+ // res.tempFilePath
|
|
|
+ fileList.value.push({
|
|
|
+ name: fileName,
|
|
|
+ filePath: res.tempFilePath.replace(".bin", ".png")
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail () {
|
|
|
+ toast.warning("下载文件失败, 请重试")
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 预览文件 (区分文件&图片)
|
|
|
+function previewFile(filePath) {
|
|
|
+ uni.openDocument({
|
|
|
+ filePath: filePath,
|
|
|
+ success () {},
|
|
|
+ fail () {
|
|
|
+ toast.warning("打开文件失败, 请重试")
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // uni.downloadFile({
|
|
|
+ // url: filePath,
|
|
|
+ // success: (res) => {
|
|
|
+ // console.log('previewFile res: ', res.tempFilePath);
|
|
|
+ // uni.openDocument({
|
|
|
+ // filePath: res.tempFilePath,
|
|
|
+ // success () {},
|
|
|
+ // fail () {
|
|
|
+ // toast.warning("打开文件失败, 请重试")
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // },
|
|
|
+ // fail () {
|
|
|
+ // toast.warning("下载文件失败, 请重试")
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+
|
|
|
+ // 图片预览
|
|
|
+ // let imgUrl = props.url || props.url
|
|
|
+ // uni.previewImage({
|
|
|
+ // current: 0,
|
|
|
+ // urls: [imgUrl],
|
|
|
+ // })
|
|
|
+}
|
|
|
+
|
|
|
+// 移除文件
|
|
|
+function removeFile(index) {
|
|
|
+ fileList.value.splice(index, 1)
|
|
|
+ if (accept.value == "all" && fileList.value.length == 0) {
|
|
|
+ message.confirm({
|
|
|
+ msg: "文件已全部移除, 是否重新上传?",
|
|
|
+ closeOnClickModal: false,
|
|
|
+ }).then(() => {
|
|
|
+ redirectToUpload()
|
|
|
+ }).catch((error) => {
|
|
|
+ reLaunchToHome()
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 打印文件 (单个打印任务)
|
|
|
+function handlePrint(filePath) {
|
|
|
// 构造提交数据
|
|
|
let params = {
|
|
|
id: formData.value.userHubId,
|
|
|
@@ -215,18 +453,7 @@ function handleUpload(file, data, options) {
|
|
|
params[option.key] = formData.value[option.key]
|
|
|
}
|
|
|
})
|
|
|
- // 远程打印
|
|
|
- // let fileData = new FormData()
|
|
|
- // fileData.appendFile("file", file.url);
|
|
|
- // printFile(params, fileData.getData().buffer, fileData.getData().contentType)
|
|
|
- // .then((res: any) => {
|
|
|
- // if (res.code === 0 && res.body) {
|
|
|
- // console.log('res.body: ', res.body);
|
|
|
- // }
|
|
|
- // })
|
|
|
- // .catch((e) => {})
|
|
|
-
|
|
|
- let queryParams = Object.entries(params).map(([key, value]) => {
|
|
|
+ const queryParams = Object.entries(params).map(([key, value]) => {
|
|
|
return `${key}=${encodeURIComponent(value)}`;
|
|
|
}).join('&');
|
|
|
|
|
|
@@ -235,37 +462,31 @@ function handleUpload(file, data, options) {
|
|
|
});
|
|
|
uni.uploadFile({
|
|
|
url: `${baseUrl}/sys/wx/userHub/print?${queryParams}`,
|
|
|
- filePath: file.url,
|
|
|
+ filePath: filePath,
|
|
|
name: 'file', // 这里根据后端需要的字段来定义
|
|
|
- fileType: options.fileType,
|
|
|
- formData, // 如果需要额外的 formData
|
|
|
success: (res: any) => {
|
|
|
if (res.statusCode === 200 && JSON.parse(res.data).code === 0) {
|
|
|
message.confirm({
|
|
|
msg: "打印成功, 是否继续打印?",
|
|
|
closeOnClickModal: false,
|
|
|
}).then(() => {
|
|
|
- hasFile.value = false
|
|
|
fileList.value = []
|
|
|
printerOptions.value = []
|
|
|
formData.value = {
|
|
|
printer: ""
|
|
|
}
|
|
|
+ if (accept.value == "all") {
|
|
|
+ redirectToUpload()
|
|
|
+ }
|
|
|
}).catch((error) => {
|
|
|
- uni.reLaunch({
|
|
|
- url: `/pages/index/index`,
|
|
|
- })
|
|
|
+ reLaunchToHome()
|
|
|
})
|
|
|
} else {
|
|
|
- toast.error('上传打印失败, 请重试')
|
|
|
- hasFile.value = false
|
|
|
- fileList.value = []
|
|
|
+ toast.warning('上传打印失败, 请重试')
|
|
|
}
|
|
|
},
|
|
|
fail: (error) => {
|
|
|
toast.error('上传打印失败, 请重试')
|
|
|
- hasFile.value = false
|
|
|
- fileList.value = []
|
|
|
},
|
|
|
complete: () => {
|
|
|
uni.hideLoading()
|
|
|
@@ -273,78 +494,58 @@ function handleUpload(file, data, options) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-function validateFileList(value: any) {
|
|
|
- if (isArray(value) && value.length) {
|
|
|
- return Promise.resolve()
|
|
|
- } else {
|
|
|
- return Promise.reject()
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
+// 处理提交打印 (支持批量)
|
|
|
function handleSubmit() {
|
|
|
- if (!hasFile.value) {
|
|
|
+ if (fileList.value.length == 0) {
|
|
|
toast.warning('请先上传文件')
|
|
|
return
|
|
|
}
|
|
|
- form.value
|
|
|
- .validate()
|
|
|
- .then(({ valid, errors }) => {
|
|
|
- if (valid) {
|
|
|
- uploader.value.submit()
|
|
|
- } else {
|
|
|
- console.log('errors: ', errors);
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-function getPrinterList() {
|
|
|
- let params = { id: "" }
|
|
|
- getUserHubPrints(params)
|
|
|
- .then((res: any) => {
|
|
|
- if (res.code === 0 && res.body) {
|
|
|
- printerList.value = res.body || []
|
|
|
- }
|
|
|
- })
|
|
|
- .catch((e) => {})
|
|
|
+ form.value.validate().then(({ valid }) => {
|
|
|
+ if (valid) {
|
|
|
+ // TODO: 批量打印
|
|
|
+ handlePrint(fileList.value[0].filePath)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
-function handlePrinterChange(item: any) {
|
|
|
- let obj = printerList.value.find(i => i.id == item.value) || {}
|
|
|
- let params = {
|
|
|
- id: obj.userHubId,
|
|
|
- printer: obj.name,
|
|
|
- }
|
|
|
- getUserHubAttr(params)
|
|
|
- .then((res: any) => {
|
|
|
- if (res.code === 0 && res.body) {
|
|
|
- printerOptions.value = res.body || []
|
|
|
- let _formData = {
|
|
|
- printer: item.value,
|
|
|
- userHubId: obj.userHubId,
|
|
|
- printerName: obj.name,
|
|
|
- }
|
|
|
- if (printerOptions.value.length) {
|
|
|
- printerOptions.value.forEach(option => {
|
|
|
- // _formData[option.key] = option.def
|
|
|
- switch(option.type) {
|
|
|
- case "rang":
|
|
|
- _formData[option.key] = option.def ? option.def.split(',') : [option.min, '']
|
|
|
- break;
|
|
|
- default:
|
|
|
- _formData[option.key] = option.def
|
|
|
- }
|
|
|
- });
|
|
|
- formData.value = _formData
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- .catch((e) => {
|
|
|
- })
|
|
|
- .finally(() => {})
|
|
|
+// 处理系统文件webview传入
|
|
|
+function base64ToTempFilePath(fileName, base64Data, success, fail) {
|
|
|
+ const fs = uni.getFileSystemManager()
|
|
|
+ // const fileName = 'temp_' + Date.now() + '.png' // 自定义文件名,可根据需要修改
|
|
|
+ const filePath = uni.env.USER_DATA_PATH + '/' + fileName
|
|
|
+ const buffer = uni.base64ToArrayBuffer(base64Data)
|
|
|
+ fs.writeFile({
|
|
|
+ filePath,
|
|
|
+ data: buffer,
|
|
|
+ encoding: 'binary',
|
|
|
+ success() {
|
|
|
+ success && success(filePath)
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ fail && fail()
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
onLoad((option) => {
|
|
|
- if (option && option.accept) accept.value = option.accept
|
|
|
+ if (option && option.accept) {
|
|
|
+ accept.value = option.accept
|
|
|
+ // 处理系统文件--all: 从webview上传的文件
|
|
|
+ if (option.accept == "all" && uni.getStorageSync('fileList')) {
|
|
|
+ fileList.value = uni.getStorageSync('fileList');
|
|
|
+ uni.removeStorageSync('fileList');
|
|
|
+
|
|
|
+ fileList.value.forEach(item => {
|
|
|
+ item.file = item.file.split('base64,')[1]
|
|
|
+ base64ToTempFilePath(item.name, item.file, (filePath) => {
|
|
|
+ console.log('转换成功,临时地址为:', filePath)
|
|
|
+ item.filePath = filePath
|
|
|
+ }, function() {
|
|
|
+ toast.warning('文件转换失败,请重试')
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
getPrinterList()
|
|
|
})
|
|
|
</script>
|
|
|
@@ -364,60 +565,45 @@ onLoad((option) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-.inline-txt {
|
|
|
- display: inline-block;
|
|
|
- font-size: 14px;
|
|
|
- margin: 0 8px;
|
|
|
- color: rgba(0, 0, 0, 0.45);
|
|
|
- vertical-align: middle;
|
|
|
-}
|
|
|
-
|
|
|
-:deep(.wd-radio-group) {
|
|
|
- padding: 0 !important;
|
|
|
- .wd-radio {
|
|
|
- padding-top: 0 !important;
|
|
|
- }
|
|
|
-}
|
|
|
:deep(.wd-upload__mask) {
|
|
|
display: none !important;
|
|
|
}
|
|
|
+
|
|
|
:deep(.img-btn .wd-img__image) {
|
|
|
width: 160rpx;
|
|
|
height: 160rpx;
|
|
|
border-radius: 40rpx;
|
|
|
}
|
|
|
-// :deep(.wd-upload__evoke) {
|
|
|
-// width: 80rpx;
|
|
|
-// height: 80rpx;
|
|
|
-// margin-bottom: 0;
|
|
|
-// border-radius: 100%;
|
|
|
-// }
|
|
|
-// :deep(.wd-upload) {
|
|
|
-// display: flex;
|
|
|
-// }
|
|
|
-// :deep(.wd-upload__evoke-num) {
|
|
|
-// display: none;
|
|
|
-// }
|
|
|
-// :deep(.wd-icon) {
|
|
|
-// font-size: 50rpx;
|
|
|
-// }
|
|
|
-// :deep(.img-btn .wd-img__image) {
|
|
|
-// width: 80rpx;
|
|
|
-// height: 80rpx;
|
|
|
-// border-radius: 40rpx;
|
|
|
-// }
|
|
|
-// :deep(.wd-upload__preview) {
|
|
|
-// display: none !important;
|
|
|
-// }
|
|
|
-// :deep(.gray-btn.wd-button) {
|
|
|
-// width: 80rpx;
|
|
|
-// height: 80rpx;
|
|
|
-// background-color: #ddd;
|
|
|
-// border-radius: 40rpx;
|
|
|
-// }
|
|
|
-// :deep(.form-ipt) {
|
|
|
-// padding-right: 0 !important;
|
|
|
-// padding-left: 0 !important;
|
|
|
-// }
|
|
|
+
|
|
|
+.file-item {
|
|
|
+ margin-bottom: 8rpx;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+
|
|
|
+ .item-icon {
|
|
|
+ display: flex;
|
|
|
+ width: 40rpx;
|
|
|
+ height: 40rpx;
|
|
|
+ margin-right: 8rpx;
|
|
|
+ }
|
|
|
+ .item-name {
|
|
|
+ flex: 1;
|
|
|
+ word-break: break-all;
|
|
|
+ }
|
|
|
+ .item-del {
|
|
|
+ display: flex;
|
|
|
+ width: 40rpx;
|
|
|
+ height: 40rpx;
|
|
|
+ margin-left: 8rpx;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.inline-txt {
|
|
|
+ display: inline-block;
|
|
|
+ font-size: 28rpx;
|
|
|
+ margin: 0 16rpx;
|
|
|
+ color: rgba(0, 0, 0, 0.45);
|
|
|
+ vertical-align: middle;
|
|
|
+}
|
|
|
</style>
|
|
|
|