1
Showing
4 changed files
with
122 additions
and
8 deletions
... | @@ -99,7 +99,7 @@ export const formdata = (url, data) => { | ... | @@ -99,7 +99,7 @@ export const formdata = (url, data) => { |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
102 | export const request = { | 102 | /*export const request = { |
103 | post(url, data) { | 103 | post(url, data) { |
104 | return axios.post(`${requestDomain}${url}`, data); | 104 | return axios.post(`${requestDomain}${url}`, data); |
105 | }, | 105 | }, |
... | @@ -127,5 +127,106 @@ export const request = { | ... | @@ -127,5 +127,106 @@ export const request = { |
127 | } | 127 | } |
128 | return fullUrl; | 128 | return fullUrl; |
129 | }, | 129 | }, |
130 | /!*test*!/ | ||
131 | };*/ | ||
132 | |||
133 | export const request = { | ||
134 | |||
135 | post(url, data) { | ||
136 | //return axios.post(`${requestDomain}${url}`, data); | ||
137 | let requestUrl = url.indexOf('://') >= 0 ? `${url}` : `${requestDomain}${url}` | ||
138 | return axios.post(requestUrl, data) | ||
139 | }, | ||
140 | get(url, data) { | ||
141 | //return axios.get(`${requestDomain}${url}`, { params: data }); | ||
142 | let requestUrl = url.indexOf('://') >= 0 ? `${url}` : `${requestDomain}${url}` | ||
143 | return axios.get(requestUrl, { | ||
144 | params: data | ||
145 | }) | ||
146 | }, | ||
147 | form(url, params) { | ||
148 | let formData = new FormData() //使用formData对象 | ||
149 | for (let key in params) { | ||
150 | formData.append(key, params[key]) | ||
151 | } | ||
152 | let requestUrl = url.indexOf('://') >= 0 ? `${url}` : `${requestDomain}${url}` | ||
153 | return axios.post(requestUrl, formData, formDataHeaders) | ||
154 | }, | ||
155 | build(url, params) { | ||
156 | let fullUrl = `${requestDomain}${url}` | ||
157 | let split = '' | ||
158 | for (let key in params) { | ||
159 | if (split) { | ||
160 | split = '&' | ||
161 | } else { | ||
162 | split = '?' | ||
163 | } | ||
164 | fullUrl += split + key + '=' + params[key] | ||
165 | } | ||
166 | return fullUrl | ||
167 | }, | ||
130 | /*test*/ | 168 | /*test*/ |
131 | }; | 169 | postTest(url, data) { |
170 | axios({ // 用axios发送post请求 | ||
171 | method: 'post', | ||
172 | url: `${requestDomain}${url}`, // 请求地址 | ||
173 | data: data, // 参数 | ||
174 | responseType: 'blob' // 表明返回服务器返回的数据类型 | ||
175 | }).then(res => { // 处理返回的文件流 | ||
176 | console.log('请求头:', res.headers) | ||
177 | console.log('res的数据:', res) | ||
178 | const filename = res.headers['content-disposition'].split('=')[1] | ||
179 | console.log('文件名:', filename) | ||
180 | const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })//new Blob([res])中不加data就会返回下图中[objece objece]内容(少取一层) | ||
181 | const elink = document.createElement('a') | ||
182 | elink.download = filename | ||
183 | elink.style.display = 'none' | ||
184 | elink.href = URL.createObjectURL(blob) | ||
185 | document.body.appendChild(elink) | ||
186 | elink.click() | ||
187 | document.body.removeChild(elink) | ||
188 | URL.revokeObjectURL(elink.href) // 释放URL 对象 | ||
189 | |||
190 | }) | ||
191 | |||
192 | var xhr = new XMLHttpRequest() | ||
193 | //xhr.open("POST", "https://ow.go.qudone.com/zlzmapi/admin/member/export/test", true); | ||
194 | xhr.open('POST', 'http://127.0.0.1:8011/zlzmapi/admin/member/export/test', true) | ||
195 | xhr.setRequestHeader('adminSessionId', 'a91986990ed049bebd0b4ab67d346229') | ||
196 | xhr.responseType = 'blob' | ||
197 | xhr.onload = function() { | ||
198 | if (this.status === 200) { | ||
199 | //var blob = new Blob([this.response], {type: 'application/vnd.ms-excel;charset=ISO8859-1'}); | ||
200 | var blob = new Blob([this.response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) | ||
201 | console.log('打印response:', this) | ||
202 | var a = document.createElement('a') | ||
203 | var url = window.URL.createObjectURL(blob) | ||
204 | a.href = url | ||
205 | document.body.appendChild(a) | ||
206 | a.click() | ||
207 | } | ||
208 | } | ||
209 | xhr.send() | ||
210 | |||
211 | /* return axios.post(`${requestDomain}${url}`, data, formDataHeaders).then(res => { | ||
212 | let fileName = res.headers['Content-Disposition'] | ||
213 | console.log('文件名:', fileName) | ||
214 | console.log('res的数据:', res) | ||
215 | console.log('res的data的数据:', res.data) | ||
216 | console.log('测试导出2') | ||
217 | //将文件流转成blob形式 | ||
218 | const blob = new Blob([res.data], { type: 'application/vnd.ms-excel;charset=utf-8' }) | ||
219 | console.log('blob的值:', blob) | ||
220 | const elink = document.createElement('a') | ||
221 | elink.style.display = 'none' | ||
222 | elink.href = URL.createObjectURL(blob) | ||
223 | document.body.appendChild(elink) | ||
224 | elink.click() | ||
225 | URL.revokeObjectURL(elink.href) // 释放URL 对象 | ||
226 | document.body.removeChild(elink) | ||
227 | /!* let objectUrl = URL.createObjectURL(blob) | ||
228 | window.location.href = objectUrl | ||
229 | *!/ | ||
230 | })*/ | ||
231 | } | ||
232 | } | ... | ... |
... | @@ -42,7 +42,9 @@ | ... | @@ -42,7 +42,9 @@ |
42 | </el-time-picker> | 42 | </el-time-picker> |
43 | </el-form-item> | 43 | </el-form-item> |
44 | <el-form-item label="地点:" prop="city"> | 44 | <el-form-item label="地点:" prop="city"> |
45 | <el-row :gutter="5"> | 45 | <el-input v-model="publicForm.city" maxlength="100" |
46 | show-word-limit></el-input> | ||
47 | <!-- <el-row :gutter="5"> | ||
46 | <el-col :span="7"> | 48 | <el-col :span="7"> |
47 | <el-select | 49 | <el-select |
48 | v-model="publicForm.province" | 50 | v-model="publicForm.province" |
... | @@ -72,7 +74,7 @@ | ... | @@ -72,7 +74,7 @@ |
72 | ></el-option> | 74 | ></el-option> |
73 | </el-select> | 75 | </el-select> |
74 | </el-col> | 76 | </el-col> |
75 | </el-row> | 77 | </el-row>--> |
76 | </el-form-item> | 78 | </el-form-item> |
77 | <el-form-item label="报名:" prop="enroll"> | 79 | <el-form-item label="报名:" prop="enroll"> |
78 | <el-input v-model="publicForm.enroll" maxlength="200" | 80 | <el-input v-model="publicForm.enroll" maxlength="200" | ... | ... |
... | @@ -12,10 +12,7 @@ | ... | @@ -12,10 +12,7 @@ |
12 | v-loading="loading" | 12 | v-loading="loading" |
13 | > | 13 | > |
14 | <el-table-column label="活动标题" prop="title"></el-table-column> | 14 | <el-table-column label="活动标题" prop="title"></el-table-column> |
15 | <el-table-column label="地点" prop="province"> | 15 | <el-table-column label="地点" prop="city"> |
16 | <template slot-scope="scope"> | ||
17 | {{scope.row.province}}-{{scope.row.city}} | ||
18 | </template> | ||
19 | </el-table-column> | 16 | </el-table-column> |
20 | <el-table-column label="报名" prop="enroll"></el-table-column> | 17 | <el-table-column label="报名" prop="enroll"></el-table-column> |
21 | <el-table-column label="开始时间"> | 18 | <el-table-column label="开始时间"> | ... | ... |
-
Please register or sign in to post a comment