Commit 4399ce35 authored by Facius's avatar Facius

feat: 维修记账-填写

parent 2bedbe12
Pipeline #2796 canceled with stages
//吊起设备原生相机相册取得文件,并自动上传七牛,返回七牛key,domain,本地file信息
function getPhoto(token, type = 2, count = 1, showLoading = true) {
return new Promise((resolve, reject) => {
let types = [['camera'], ['album'] , ['album', 'camera']]
let sourceType = types[type]
uni.chooseImage({
count: count, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: sourceType, //从相册选择
success: function(res) {
if (showLoading) {
uni.showLoading({
title: '上传中...',
})
}
console.log('-------------:', res)
uploads(res.tempFiles, token)
.then((result) => {
let keys = []
let urls = []
if (result) {
for (var item of result) {
keys.push(item.key)
urls.push(item.url)
}
}
resolve({
key: keys,
files: urls
})
})
.catch((msg) => {
reject(msg)
})
// var state = 0 // 上传第几张图片
// var imgList = [] // 保存图片数组
// var uploadNum = res.tempFiles.length // 上传数组的长度
// //上传七牛
// for (let i = 0; i < uploadNum; i++) {
// let filePath = res.tempFiles[i].path //为需要上传的文件
// upload(filePath, token)
// .then((msg) => {
// //最后七牛返回的key
// state++
// imgList.push(msg)
// if (state == uploadNum) {
// resolve({
// key: imgList,
// files: res.tempFiles,
// })
// }
// })
// .catch((msg) => {
// reject(msg)
// })
// }
},
complete: function() {},
})
})
}
function uploadOneWHPhoto(token, type = 2, block) {
return new Promise((resolve, reject) => {
let types = [['camera'], ['album'] , ['album', 'camera']]
let sourceType = types[type]
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: sourceType, //从相册选择
success: function(res) {
if (res.tempFilePaths.length > 0) {
let filePath = res.tempFilePaths[0]
uni.getImageInfo({
src: filePath,
success: function (image) {
var key = new Date().getTime() + Math.random(1000) + filePath.split('/').pop().replace(/\_/g, '') //key为自定义文件名
key = key.replace(/\.(?=.*\.)/g, '')
key = key.replace(/\./, `_${image.width}_${image.height}_.`)
if (block) block(filePath, key)
uni.uploadFile({
url: uploadUrl, // default ecn华北的地址,在七牛云中选择对应位置的网址
filePath: filePath,
name: 'file',
formData: {
token: token,
key: key,
},
complete: (res) => {
if (res.statusCode === 200) {
resolve(JSON.parse(res.data).key || JSON.parse(res.data).src)
} else {
reject(res.errMsg)
}
},
})
}
});
}
},
complete: function() {},
})
})
}
function uploads(list, token) {
return new Promise((resolve, reject) => {
var state = 0 // 上传第几张图片
var imgList = [] // 保存图片数组
var uploadNum = list.length // 上传数组的长度
//上传七牛
for (let i = 0; i < uploadNum; i++) {
let filePath = list[i].path || list[i].url //为需要上传的文件
upload(filePath, token)
.then((msg) => {
//最后七牛返回的key
state++
imgList.push({key: msg, url: filePath})
if (state == uploadNum) {
resolve(imgList)
}
})
.catch((msg) => {
reject(msg)
})
}
})
}
function uploadFiles(token, tempFilePaths, success, progress, error ) {
var count = 0 // 上传第几张图片
var fileList = []
var tasks = []
for (let i = 0; i < tempFilePaths.length; i++) {
let item = {...tempFilePaths[i]}
let filePath = item.path
var key = new Date().getTime() + Math.random(1000) + filePath.split('/').pop().replace(/\=/g, '') //key为自定义文件名
key = key.replace(/\.(?=.*\.)/g, '')
var task = uni.uploadFile({
url: uploadUrl, // default ecn华北的地址,在七牛云中选择对应位置的网址
filePath: filePath,
name: 'file',
formData: {
token: token,
key: key,
},
complete: (res) => {
if (res.statusCode === 200) {
fileList.push({path: filePath, url: JSON.parse(res.data).key || JSON.parse(res.data).src})
count++
if (count == tempFilePaths.length) {
success(fileList)
}
} else {
error(item,res.errMsg)
}
}
})
task.onProgressUpdate((res) => {
progress({...item, progress: res.progress, task: task})
});
tasks[i] = task
}
}
const uploadUrl = 'https://up-z2.qiniup.com'
//上传七牛
function upload(filePath, token, duration = '') {
return new Promise((resolve, reject) => {
var key = new Date().getTime() + Math.random(1000) + filePath.split('/').pop().replace(/\=/g, '') //key为自定义文件名
key = key.replace(/\.(?=.*\.)/g, '')
if (duration) key = key.replace(/\./, `durationTime=${duration * 1000}.`)
uni.uploadFile({
url: uploadUrl, // default ecn华北的地址,在七牛云中选择对应位置的网址
filePath: filePath,
name: 'file',
formData: {
token: token,
key: key,
},
complete: (res) => {
if (res.statusCode === 200) {
resolve(JSON.parse(res.data).key || JSON.parse(res.data).src)
} else {
reject(res.errMsg)
}
},
})
})
}
export default {
uploadUrl,
upload,
uploads,
getPhoto,
uploadOneWHPhoto,
uploadFiles
}
<template> <template>
<u-navbar <u-navbar
:back-text="title" :title="title"
title-color="191C27"
title-bold
:back-text="backText"
:back-text-style="backTextStyle" :back-text-style="backTextStyle"
:background="background" :background="background"
:border-bottom="false" :border-bottom="false"
> >
<view <view
v-if="text || image"
class="slot-wrap" class="slot-wrap"
slot="right" slot="right"
hover-class="u-hover-class" hover-class="u-hover-class"
...@@ -24,6 +28,10 @@ export default { ...@@ -24,6 +28,10 @@ export default {
type: String, type: String,
default: '', default: '',
}, },
backText: {
type: String,
default: '',
},
text: { text: {
type: String, type: String,
default: '', default: '',
......
<template> <template>
<u-upload <UploadImages
ref="upload-images"
:max-count="maxCount" :max-count="maxCount"
:width="width" :width="width"
:height="height" :height="height"
...@@ -7,9 +8,7 @@ ...@@ -7,9 +8,7 @@
:file-list="fileList" :file-list="fileList"
:auto-upload="autoUpload" :auto-upload="autoUpload"
:show-progress="false" :show-progress="false"
:deletable="deletable" :show-add="showAdd"
:show-upload-list="showUploadList"
:preview-full-image="previewFullImage"
@on-list-change="handleListChange" @on-list-change="handleListChange"
> >
<view <view
...@@ -19,16 +18,18 @@ ...@@ -19,16 +18,18 @@
:style="slotStyle" :style="slotStyle"
hover-stay-time="150" hover-stay-time="150"
> >
<u-icon name="plus" :size="addSize" color="#999999"></u-icon> <u-icon name="plus" :size="addSize" color="#D8D8D8"></u-icon>
</view> </view>
</u-upload> </UploadImages>
</template> </template>
<script> <script>
import upload from '@/utils/upload.js' import upload from '@/common/upload'
import {getQiNiuToken} from "@/api/common/index.js" import UploadImages from '@/components/upload/u-upload'
export default { export default {
components: {
UploadImages,
},
props: { props: {
// 给fileList赋初始值用 // 给fileList赋初始值用
list: { list: {
...@@ -65,22 +66,10 @@ export default { ...@@ -65,22 +66,10 @@ export default {
type: Boolean, type: Boolean,
default: false default: false
}, },
hide:{ showAdd: {
type: Boolean, type: Boolean,
default: false default: true
}, },
deletable:{
type: Boolean,
default: true
},
previewFullImage:{
type: Boolean,
default: false
},
showUploadList:{
type: Boolean,
default: true
}
}, },
data() { data() {
return { return {
...@@ -172,10 +161,13 @@ export default { ...@@ -172,10 +161,13 @@ export default {
} }
}, },
getQiniuToken() { getQiniuToken() {
getQiNiuToken().then((res) => { // this.$u.api.getQiNiuToken().then((res) => {
this.qiniuToken = res // this.qiniuToken = res
}) // })
}, },
selectFile() { // 触发选择图片;不能改文件名,外部要调
this.$refs['upload-images'].selectFile()
}
}, },
} }
</script> </script>
......
This diff is collapsed.
This diff is collapsed.
<template> <template>
<view class="maintain-detail"> <view class="maintain-detail">
<NavbarRight <NavbarRight
title="详情" backText="详情"
text="删除" text="删除"
:image="deleteImage" :image="deleteImage"
@click="handlClickDelete" @click="handlClickDelete"
......
<template> <template>
<view class="maintain-bill"> <view class="maintain-bill">
<NavbarRight <NavbarRight
title="维修记账" backText="维修记账"
text="导出账单" text="导出账单"
imageWidth="20" imageWidth="20"
:image="outImage" :image="outImage"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment