1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<template>
<view class="content">
<view class="jisuanqi" @click="uploadExcel" style="margin-top:100rpx;">
导入
</view>
<view class="jisuanqi" @click="exportExcel" style="margin-top:100rpx;">
导出
</view>
<!-- <view class="jisuanqi" @click="showCalendar=true" style="margin-top:100rpx;">
选择日期
</view>
-->
<view class="content-confirm" style="margin-top:100rpx;">
日期选择{{searchDate}}
<!-- <calendar-select v-model="showCalendar"
maxDate="2021-6-20"
:addOrRemoveData="addOrRemoveData"
mode="range"
:altPrice="dataPrice"
@change="changeDate"></calendar-select>
-->
<!--
<button @click="open">打开弹窗</button>
<uni-popup ref="popup" type="bottom" border-radius="10px 10px 0 0">
<miku-calendar
:calendarBg="'#fff'"
:dateRange="[new Date('2024/02/01').getTime(),new Date('2024/02/27').getTime()]"
:dateRangeMax="365"
@dateRangeMaxDeal="dateRangeMaxDeal"
mode='dateRange'
:showArrow="true"
themeColor="rgb(100,124,203)"
arrowColor="rgb(100,124,203)"
@confirm = "calendarConfirm"
></miku-calendar>
</uni-popup> -->
</view>
<!-- <web-view :src="localUrl" @message="handlePostMessage"></web-view> -->
</view>
</template>
<script>
import * as XLSX from '@/common/excel.js'
// import CalendarSelect from '@/components/calendar-select/calendar-select.vue'
// import mikuCalendar from "@/components/miku-calendar/mikuCalendar.vue"
var that;
export default {
components: {
// CalendarSelect,
// mikuCalendar
},
data() {
return {
searchDate: '',
date: new Date('2023/09/20').getTime(),
title: "app端导出excel",
successTip: "",
// localUrl: '../../hybrid/html/local.html' // 本地页面的 URL
localUrl: 'http://www.minestar.cn/index.html', // 本地页面的 URL
excelList:[{
'ctime':22, 'payname':22, 'remark':22,'typename':22,'type':22,'money':22
}], //接口提供数据
showCalendar: false,
dataPrice: [ // 日历上的价格
{
date: '2021-4-23',
price: 98
},
{
date: '2021-4-28',
price: 108
},
{
date: '2021-4-29',
price: 98
}
],
addOrRemoveData: ['2021-04-23', '2021-04-27']
}
},
onLoad() {
// 获取小程序的本地文件路径
// this.localUrl = `/hybrid/html/local.html`;
},
methods: {
open(){
// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ,type 属性将失效 ,仅支持 ['top','left','bottom','right','center']
this.$refs.popup.open('center')
},
calendarConfirm(e){
console.log(e)
const formattedDates = e.map(date => date.split(' ')[0]);
this.searchDate = formattedDates
this.$refs.popup.close()
},
dateRangeMaxDeal(e){
console.log('超过最大连选天数:',e)
},
// 获取选中的日期
changeDate(data) {
console.log(data)
},
uploadExcel(){
// wx.miniapp.chooseFile({
// success(res) {
// const tempFiles = res.tempFiles
// console.log('wx.miniapp.chooseFile success', tempFiles)
// },
// fail(err) {
// console.log('wx.miniapp.chooseFile fail', err)
// }
// })
wx.chooseMessageFile({
count: 1,
type: 'file',
extension: ['.xlsx', '.xls'],
success: function(res) {
console.log("文件上传", res);
uni.uploadFile({
url: config.baseUrl + '/product/importProduct', //文件上传的接口地址
filePath: res.tempFiles[0].path,
name: 'excel', //接口需要的参数名
header: {
'Authorization': uni.getStorageSync('lifeData').vuex_token
},
success(uploadRes) {
uni.showToast({
icon: 'none',
title: '上传成功'
});
that.pageNum = 1
that.getProjectList()
},
fail(uploadErr) {
console.log('上传失败', uploadErr);
// 处理上传失败后的逻辑
}
});
},
fail(err) {
console.log('选择文件失败', err);
// 处理选择文件失败后的逻辑
}
});
},
// 导出excel
exportExcel() {
const fileName='账单明细'
const header = ['ctime', 'payname', 'remark','typename','type','money'];
const headerName = { ctime: '记账时间', payname: '支付类型', remark: '备注' ,typename:'消费类型',type:'支出2/收入1',money:'价格(元)'};
const ExcelData = this.excelList;//列表数据
uni.showToast({
title: "导出中,请稍后...",
duration:3000,
icon: 'none'
})
XLSX.excel_exprot(ExcelData, header, headerName,fileName)
},
// webview向外部发送消息
handlePostMessage: function(data) {
console.log("接收到消息:" + JSON.stringify(data.detail));
/**
* 数据机构
*/
// {
// "data": [{
// "selectListLv1": "[\"1\",\"2\"]",
// "selectListLv2": "[\"1-1\",\"2\"]",
// "dataArr": [{
// "设计孔深": 1,
// "巷道": "1-2",
// "分段": "1-1",
// "孔号": "1-3",
// "中段": 1
// }]
// }]
// }
const sonPageData = data.detail
if(sonPageData.type === 'goHome'){ // 返回上一页
uni.reLaunch({
url: '/pages/home/home'
})
return
}
if(sonPageData.data[0].errorTip){
uni.showModal({
title: '信息提示',
content: sonPageData.data[0].errorTip,
showCancel: false
})
return
}
uni.setStorageSync('importDataList', sonPageData.data[0]['dataArr'])
uni.setStorageSync('selectListLv1', sonPageData.data[0]['selectListLv1'])
uni.setStorageSync('selectListLv2', sonPageData.data[0]['selectListLv2'])
uni.reLaunch({
url: '/pages/home/home'
})
},
}
}
</script>
<style>
::v-deep .uni-popup .uni-popup__wrapper{
display: block;
position: relative;
width: 80vw;
}
</style>