Commit 1ec834a4 authored by Facius's avatar Facius
parents 9a9e326e 94481f74
Pipeline #2767 canceled with stages
import request from "@/utils/request.js"
export function getQiNiuToken(data) {
return request({
url: `/rest/file/token/get`,
method: 'get',
data
})
}
\ No newline at end of file
<template> <template>
<u-popup v-model="show" border-radius="24" safe-area-inset-bottom mode="bottom"> <u-popup v-model="show" border-radius="24" :custom-style="{ 'background-color': '#F6F7FA' }" safe-area-inset-bottom mode="bottom">
<view class="billing-details"> <view class="content">
<xl-calculator @closeCalculatorPopup="closeCalculatorPopup"></xl-calculator> <view class="billing">
<view class="billing-head">
<view class="billing-head-location ">
<u-icon name="map" class="billing-head-location-icon"></u-icon>
<view class="billing-head-location-address ellipsis">{{ form.location }}</view>
</view>
<view class="billing-head-close"><u-icon name="close"></u-icon></view>
</view>
<view class="billing-type">
<checkbox-groups :checked="form.type" :custom-style="customStyle" :options="billingTypeOptions" @handleClick="billingTypeChange"></checkbox-groups>
<view class="billing-type-date" @click="openCalendarPopup">
<text>{{ form.date }}</text>
<u-icon name="arrow-down-fill" class="billing-type-date-icon"></u-icon>
</view>
</view>
<view class="billing-money ellipsis">
<text>¥</text>
<text>{{ form.money }}</text>
</view>
<view class="billing-category"><billing-category :checked="form.category" @handleClick="billingCategoryChange"></billing-category></view>
<view class="billing-remark">
<view class="billing-remark-upload" @click="handleClickChangeImage">
<u-icon name="camera"></u-icon>
<view class="billing-remark-upload-icon">
<u-icon name="checkbox-mark"></u-icon>
</view>
</view>
<view class="billing-remark-input">
<u-input
type="text"
v-model="form.remark"
placeholder-style="color: #02A074;"
placeholder="点击填写备注"
:clearable="false"
class="form-input"
maxlength="200"
/>
</view>
</view>
</view>
<!-- 计算器 -->
<view class="billing-calculator"><ab-calculator @change="calculatorChange" @sure="calculatorSure"></ab-calculator></view>
<!-- 日历 -->
<calendar-popup :date="form.date" ref="calendar-popup" @confirm="calendarChange"></calendar-popup>
</view> </view>
</u-popup> </u-popup>
</template> </template>
<script> <script>
import XlCalculator from '@/components/xl-calculator/xl-calculator.nvue'; import AbCalculator from '@/components/calculator';
import CheckboxGroups from '@/components/checkbox-groups/checkbox-groups.vue';
import CalendarPopup from '@/components/calendar-popup/calendar-popup.vue';
import BillingCategory from './components/billing-category.vue';
import { billingTypeOptions } from '@/utils/options/index';
import upload from '@/utils/upload';
export default { export default {
name: 'billing-details', name: 'billing-details',
components:{ components: {
XlCalculator AbCalculator,
CheckboxGroups,
CalendarPopup,
BillingCategory
}, },
data() { data() {
return { return {
show: false, billingTypeOptions,
show: true,
customStyle: {
width: '104rpx',
height: '48rpx',
fontSize: '24rpx'
},
form: {
type: '1',
location: '庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威庭威',
date: '2022-07-13',
money: '56465464646456544444444444444444444444444444444444',
category: '2'
},
upload: {
uploading: false,
fileList: [],
qiniuToken: ''
}
}; };
}, },
methods: { methods: {
...@@ -25,15 +94,160 @@ export default { ...@@ -25,15 +94,160 @@ export default {
close() { close() {
this.show = false; this.show = false;
}, },
closeCalculatorPopup(){ // 点击=
this.close() calculatorChange(e) {
console.log('calculatorChange', e);
this.form.money = e;
},
// 点击确认
calculatorSure(e) {
console.log('calculatorSure', e);
},
// 日历
calendarChange(e) {
console.log('calendarChange', e);
this.form.date = e;
},
billingTypeChange(e) {
console.log(e);
this.form.type = e.value;
},
openCalendarPopup() {
this.$refs['calendar-popup'].open();
},
billingCategoryChange(item) {
this.form.category = item.value;
},
// 上传组件
handleListChange(lists) {
if (lists) {
this.upload.fileList = lists;
}
},
handleClickChangeImage() {
// 上传图片
upload.getPhoto(this.upload.qiniuToken).then(res => {
console.log('upload success', res);
let param = {
id: this.camp_id
};
// switch (this.currentOperate) {
// case 'cover':
// this.info.coverUrl = this.assetUrl + res.key;
// param.coverUrl = this.info.coverUrl;
// break;
// case 'logo':
// this.info.logoUrl = this.assetUrl + res.key;
// param.logoUrl = this.info.logoUrl;
// break;
// }
// this.updateCamp(param);
});
} }
} }
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.billing-details { .billing {
padding: 32upx; color: #333333;
padding: 0 24upx;
padding-bottom: 32upx;
background-color: #ffffff;
&-head {
height: 108upx;
display: flex;
align-items: center;
justify-content: space-between;
&-location {
display: flex;
align-items: center;
font-size: 24upx;
&-icon {
margin-right: 8upx;
font-size: 28upx;
}
&-address {
width: 500upx;
}
}
&-close {
margin-left: 100upx;
width: 108upx;
height: 108upx;
display: flex;
align-items: center;
justify-content: flex-end;
font-size: 32upx;
}
}
&-type {
display: flex;
align-items: center;
justify-content: space-between;
&-date {
padding: 0 18upx;
height: 48upx;
background: #f6f7fa;
border-radius: 8upx;
display: flex;
align-items: center;
justify-content: center;
font-size: 24upx;
color: #333333;
&-icon {
color: #8d8d8d;
margin-left: 16upx;
}
}
}
&-money {
// margin-top: 8upx;
padding: 24upx 0upx;
border-bottom: 2px solid #f6f7fa;
font-size: 64upx;
font-weight: bold;
color: #333333;
line-height: 64upx;
}
&-category {
margin-bottom: -10upx;
}
&-calculator {
margin-top: -10upx;
}
&-remark {
display: flex;
&-upload {
display: flex;
width: 72upx;
height: 72upx;
background: #f6f7fa;
border-radius: 16upx;
position: relative;
align-items: center;
justify-content: center;
font-size: 38upx;
color: #333333;
&-icon {
position: absolute;
display: flex;
right: 2upx;
top: 2upx;
border-radius: 16upx;
z-index: 1;
font-size: 20upx;
color: $default-color;
}
}
&-input {
flex: 1;
padding: 0 24upx;
}
.form-input {
}
}
} }
</style> </style>
<template>
<view class="billing-category">
<view class="billing-category-item" :class="{ active: item.value === checked }" v-for="(item, index) in list" :key="index" @click="handleCheck(item)">
<view class="billing-category-item-icon"></view>
<view class="billing-category-item-text">{{item.label}}</view>
</view>
</view>
</template>
<script>
import { billingCategoryOptions } from '@/utils/options/index/index.js';
export default {
name: 'billing-category',
props: {
checked: {
type: Number | String,
default: ''
}
},
data() {
return {
list: billingCategoryOptions,
};
},
methods: {
handleCheck(item) {
this.$emit('handleClick', item);
}
}
};
</script>
<style lang="scss" scoped>
.billing-category {
display: flex;
flex-wrap: wrap;
margin-top: 24upx;
// margin-bottom: 24upx;
&-item {
padding: 0 22upx;
font-size: 28upx;
color: #8d8d8d;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-bottom: 32upx;
&-icon {
width: 72upx;
height: 72upx;
background: #f6f7fa;
border-radius: 50%;
}
&-text {
margin-top: 12upx;
font-size: 20upx;
line-height: 20upx;
color: #8d8d8d;
}
}
.active {
.billing-category-item-icon{
background-color: $default-color;
}
.billing-category-item-text {
color: #333333;
}
}
}
</style>
...@@ -436,7 +436,7 @@ export default { ...@@ -436,7 +436,7 @@ export default {
}; };
</script> </script>
<style> <style scoped>
.calculator-view { .calculator-view {
width: 100%; width: 100%;
display: flex; display: flex;
......
<template>
<u-popup v-model="show" border-radius="24" safe-area-inset-bottom mode="bottom">
<view class="calendar-popup">
<view class="calendar-popup-top">
<text class="calendar-popup-top-left" @click="close">取消</text>
<text class="calendar-popup-top-right" @click="confirm">确定</text>
</view>
<lunc-calendar
ref="lunc-calendar"
:showLunar="true"
:showMonthBg="false"
:shouChangeBtn="true"
firstDayOfWeek="sunday"
:weekend="true"
@dayChange="dayChange"
></lunc-calendar>
</view>
</u-popup>
</template>
<script>
import { parseTime } from '@/utils/common.js';
export default {
name: 'calendar-popup',
props: {
date: {
type: String,
default: () => {
return parseTime(new Date(), '{y}-{m}-{d}');
}
}
},
data() {
return {
show: false,
defaultDate: ''
};
},
mounted() {
this.$refs['lunc-calendar'].init(this.date);
},
methods: {
open() {
this.show = true;
this.$nextTick(() => {
this.$refs['lunc-calendar'].init(this.date);
});
},
close() {
this.show = false;
},
confirm() {
this.$emit('confirm', this.defaultDate);
this.close();
},
dayChange(e) {
console.log('dayChange', e);
this.defaultDate = e.date;
}
}
};
</script>
<style lang="scss" scoped>
.calendar-popup {
padding: 32upx 0;
}
.calendar-popup-top {
padding: 0 32upx;
display: flex;
align-items: center;
justify-content: space-between;
&-left {
color: rgb(96, 98, 102);
}
&-right {
color: rgb(41, 121, 255);
&:active {
opacity: 0.7;
}
}
}
</style>
<template> <template>
<view class="checkbox-group"> <view class="checkbox-group">
<view class="checkbox-group-item" :class="{ active: item.value === checked }" v-for="(item, index) in options" :key="index" @click="handleCheck(item)"> <view class="checkbox-group-item" :style="[customStyle]" :class="{ active: item.value === checked }" v-for="(item, index) in options" :key="index" @click="handleCheck(item)">
{{ item.label }} {{ item.label }}
</view> </view>
</view> </view>
...@@ -17,6 +17,10 @@ export default { ...@@ -17,6 +17,10 @@ export default {
options: { options: {
type: Array, type: Array,
default: () => [] default: () => []
},
customStyle:{
type: Object,
default: () => {}
} }
}, },
data() { data() {
...@@ -40,10 +44,11 @@ export default { ...@@ -40,10 +44,11 @@ export default {
background: #f6f7fa; background: #f6f7fa;
border-radius: 8upx; border-radius: 8upx;
font-size: 28upx; font-size: 28upx;
line-height: 80upx;
text-align: center;
color: #8d8d8d; color: #8d8d8d;
margin-right: 24upx; margin-right: 24upx;
display: flex;
align-items: center;
justify-content: center;
&:last-child { &:last-child {
margin-right: 0; margin-right: 0;
} }
......
<template>
<u-upload
:max-count="maxCount"
:width="width"
:height="height"
custom-btn
:file-list="fileList"
:auto-upload="autoUpload"
:show-progress="false"
:deletable="deletable"
:show-upload-list="showUploadList"
:preview-full-image="previewFullImage"
@on-list-change="handleListChange"
>
<view
slot="addBtn"
class="slot-btn"
hover-class="slot-btn__hover"
:style="slotStyle"
hover-stay-time="150"
>
<u-icon name="plus" :size="addSize" color="#999999"></u-icon>
</view>
</u-upload>
</template>
<script>
import upload from '@/utils/upload.js'
import {getQiNiuToken} from "@/api/common/index.js"
export default {
props: {
// 给fileList赋初始值用
list: {
type: Array,
default() {
return []
},
},
// 最大上传数量
maxCount: {
type: [String, Number],
default: 9,
},
// 是否自动上传
autoUpload: {
type: Boolean,
default: false,
},
// 内部预览图片区域和选择图片按钮的区域宽度
width: {
type: [String, Number],
default: 160,
},
// 内部预览图片区域和选择图片按钮的区域高度
height: {
type: [String, Number],
default: 160,
},
addSize: {
type: [String, Number],
default: 48,
},
uploading: {
type: Boolean,
default: false
},
hide:{
type: Boolean,
default: false
},
deletable:{
type: Boolean,
default: true
},
previewFullImage:{
type: Boolean,
default: false
},
showUploadList:{
type: Boolean,
default: true
}
},
data() {
return {
fileList: null,
qiniuToken: '',
}
},
computed: {
assetUrl() {
return process.uniEnv.qn_asset_url
},
keyList() {
let list = []
if (this.fileList) {
for (var item of this.fileList) {
if (item.key) {
list.push(item.key)
}
}
}
return list
},
slotStyle() {
return ` width:${this.width}rpx;height:${this.height}rpx;`
}
},
watch: {
list(val) {
if (val && !this.fileList) {
this.fileList = []
for (var item of val) {
this.fileList.push({
key: item,
url: item,
})
}
}
},
},
created() {
this.getQiniuToken()
},
methods: {
filterList(listA, listB) {
listA = listA || []
listB = listB || []
let list = []
for (var item of listA) {
for (var obj of listB) {
if (obj.url == item.url) {
item.key = obj.key
}
}
list.push(item)
}
return list
},
handleListChange(lists, name) {
this.fileList = this.filterList(lists, this.fileList)
let newImages = this.fileList.filter((item) => {
return item.key == undefined
})
if (newImages && newImages.length > 0) {
this.$emit('update:uploading', true)
upload
.uploads(newImages, this.qiniuToken)
.then((res) => {
let list = []
if (res) {
for (var item of res) {
list.push({
url: item.url,
key: this.assetUrl + item.key
})
}
}
this.fileList = this.filterList(this.fileList, list)
this.$emit('on-list-change', this.keyList)
console.log('upload:', this.fileList.length, this.keyList.length)
this.$emit('update:uploading', this.fileList.length != this.keyList.length)
})
.catch((msg) => {
console.log(msg)
})
} else {
this.$emit('on-list-change', this.keyList)
}
},
getQiniuToken() {
getQiNiuToken().then((res) => {
this.qiniuToken = res
})
},
},
}
</script>
<style lang="scss" scoped>
/deep/.u-add-tips {
height: 0 !important;
margin-top: 0 !important;
overflow: hidden;
}
.slot-btn {
width: 160rpx;
height: 160rpx;
display: flex;
justify-content: center;
align-items: center;
background: #F6F7FA;
border-radius: 10rpx;
margin: 10rpx;
}
.slot-btn__hover {
background-color: rgb(235, 236, 238);
}
</style>
...@@ -344,7 +344,7 @@ export default { ...@@ -344,7 +344,7 @@ export default {
}; };
</script> </script>
<style> <style scoped>
.calculator-view { .calculator-view {
width: 100%; width: 100%;
display: flex; display: flex;
......
...@@ -17,7 +17,10 @@ ...@@ -17,7 +17,10 @@
"delay" : 0 "delay" : 0
}, },
/* 模块配置 */ /* 模块配置 */
"modules" : {}, "modules" : {
"OAuth" : {},
"Payment" : {}
},
/* 应用发布信息 */ /* 应用发布信息 */
"distribute" : { "distribute" : {
/* android打包配置 */ /* android打包配置 */
...@@ -43,7 +46,11 @@ ...@@ -43,7 +46,11 @@
/* ios打包配置 */ /* ios打包配置 */
"ios" : {}, "ios" : {},
/* SDK配置 */ /* SDK配置 */
"sdkConfigs" : {} "sdkConfigs" : {
"ad" : {},
"oauth" : {},
"payment" : {}
}
} }
}, },
/* 快应用特有相关 */ /* 快应用特有相关 */
......
...@@ -21,15 +21,21 @@ ...@@ -21,15 +21,21 @@
<script> <script>
export default { export default {
name: 'calculator-popup', name: 'calculator-popup',
props: {}, props: {
date:{
type:String,
default:()=>{
return this.parseTime(new Date(), '{y}-{m}-{d}')
}
}
},
data() { data() {
return { return {
show: false, show: false,
date: '' defaultDate: ''
}; };
}, },
mounted() { mounted() {
this.date = this.parseTime(new Date(), '{y}-{m}-{d}');
this.$refs["lunc-calendar"].init(this.date) this.$refs["lunc-calendar"].init(this.date)
}, },
methods: { methods: {
...@@ -43,12 +49,12 @@ export default { ...@@ -43,12 +49,12 @@ export default {
this.show = false; this.show = false;
}, },
confirm() { confirm() {
this.$emit('confirm', this.date); this.$emit('confirm', this.defaultDate);
this.close() this.close()
}, },
dayChange(e) { dayChange(e) {
console.log('dayChange', e); console.log('dayChange', e);
this.date = e.date; this.defaultDate = e.date;
} }
} }
}; };
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</u-form-item> </u-form-item>
<u-form-item label="计划时间:" :prop="form.createdTime ? 'time' : 'createdTime'" label-position="left"> <u-form-item label="计划时间:" :prop="form.createdTime ? 'time' : 'createdTime'" label-position="left">
<view class="created-time"> <view class="created-time">
<view class="created-time-item" @click="openCalculatorPopup"> <view class="created-time-item" @click="openCalendarPopup">
<view class="created-time-item-inner"> <view class="created-time-item-inner">
<text v-if="form.createdTime">{{ form.createdTime }}</text> <text v-if="form.createdTime">{{ form.createdTime }}</text>
<text class="placeholder" v-else>选择计划日期</text> <text class="placeholder" v-else>选择计划日期</text>
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<view class="schedule-card"> <view class="schedule-card">
<u-form-item label="计划标题:" prop="title" label-position="left"> <u-form-item label="计划标题:" prop="title" label-position="left">
<u-input type="text" v-model="form.title" placeholder="请输入计划标题" :clearable="false" input-align="right" class="form-input" /> <u-input type="text" v-model="form.title" placeholder="请输入计划标题" :clearable="false" input-align="right" maxlength="100" class="form-input" />
</u-form-item> </u-form-item>
<u-form-item label="计划纪要:" prop="desc" :border-bottom="false"> <u-form-item label="计划纪要:" prop="desc" :border-bottom="false">
<u-input v-model="form.desc" type="textarea" :border="true" :height="240" :auto-height="false" :clearable="false" /> <u-input v-model="form.desc" type="textarea" :border="true" :height="240" :auto-height="false" :clearable="false" />
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<u-popup v-model="soundShow" mode="bottom" border-radius="14" safe-area-inset-bottom> <u-popup v-model="soundShow" mode="bottom" border-radius="14" safe-area-inset-bottom>
<sound-recording ref="sound-recording" @cancel="soundCancel" @confirm="soundConfirm"></sound-recording> <sound-recording ref="sound-recording" @cancel="soundCancel" @confirm="soundConfirm"></sound-recording>
</u-popup> </u-popup>
<calculator-popup ref="calculator-popup" @confirm="calculatorChange"></calculator-popup> <calendar-popup :date="form.createdTime" ref="calendar-popup" @confirm="calculatorChange"></calendar-popup>
<u-picker v-model="timeShow" mode="time" :default-time="defaultTime" :params="timeParams" @confirm="timePickerConfirm"></u-picker> <u-picker v-model="timeShow" mode="time" :default-time="defaultTime" :params="timeParams" @confirm="timePickerConfirm"></u-picker>
</view> </view>
</template> </template>
...@@ -54,13 +54,13 @@ ...@@ -54,13 +54,13 @@
<script> <script>
import SoundRecording from '@/components/sound-recording/sound-recording.vue'; import SoundRecording from '@/components/sound-recording/sound-recording.vue';
import AbButton from '@/components/common/ab-button.vue'; import AbButton from '@/components/common/ab-button.vue';
import CheckboxGroups from './components/checkbox-groups.vue'; import CheckboxGroups from '@/components/checkbox-groups/checkbox-groups.vue';
import CalculatorPopup from './components/calculator-popup.vue'; import CalendarPopup from '@/components/calendar-popup/calendar-popup.vue';
import SoundPlayer from './components/sound-player.vue'; import SoundPlayer from './components/sound-player.vue';
import { authorize, openSetting, showModal } from '@/utils/auth.js'; import { authorize, openSetting, showModal } from '@/utils/auth.js';
import { scheduleTypeOptions, scheduleSettingOptions } from '@/utils/options/schedule'; import { scheduleTypeOptions, scheduleSettingOptions } from '@/utils/options/schedule';
export default { export default {
components: { SoundRecording, CheckboxGroups, CalculatorPopup, SoundPlayer, AbButton }, components: { SoundRecording, CheckboxGroups, CalendarPopup, SoundPlayer, AbButton },
data() { data() {
return { return {
scheduleTypeOptions, scheduleTypeOptions,
...@@ -196,8 +196,8 @@ export default { ...@@ -196,8 +196,8 @@ export default {
this.form.setting = item.value; this.form.setting = item.value;
} }
}, },
openCalculatorPopup() { openCalendarPopup() {
this.$refs['calculator-popup'].open(); this.$refs['calendar-popup'].open();
}, },
calculatorChange(e) { calculatorChange(e) {
console.log('calculatorChange', e); console.log('calculatorChange', e);
......
...@@ -18,3 +18,30 @@ $base-line-height: 28upx; ...@@ -18,3 +18,30 @@ $base-line-height: 28upx;
// 主题颜色 // 主题颜色
$default-color: #02a074; $default-color: #02a074;
.ellipsis {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
}
.ellipsis-2 {
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
}
.ellipsis-3 {
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
line-clamp: 3;
-webkit-box-orient: vertical;
}
\ No newline at end of file
export const billingTypeOptions = [{
value: "1",
label: "收入"
},
{
value: "2",
label: "支出"
},
]
export const billingCategoryOptions = [{
value: "1",
label: "交通",
icon:''
},
{
value: "2",
label: "餐饮",
icon:''
},
{
value: "3",
label: "服饰",
icon:''
},
{
value: "4",
label: "购物",
icon:''
},
{
value: "5",
label: "娱乐",
icon:''
},
{
value: "6",
label: "教育",
icon:''
},
{
value: "7",
label: "材料",
icon:''
},
{
value: "8",
label: "设置",
icon:''
},
]
\ No newline at end of file
//吊起设备原生相机相册取得文件,并自动上传七牛,返回七牛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)
})
}
})
}
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
}
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