window.open post
前端代码
expExcel(){ window.open(PreURL+'company_list_exp?keyword='+this.keyword+'&area_code='+this.form.area_code+'&industry_code'+this.form.industry_code) }
后端代码
后端代码实际上走的是get方法
# 企业查询 @api.route('/company_list_exp', methods=['GET', 'POST']) def zhs_company_list_exp(): keyword = request.args['keyword'].encode(Conf.CHAR_ENCODE) area_code = request.args['area_code'] industry_code = request.args['industry_code'] params = { 'kewword': '%%%s%%' %keyword, 'area_code': '%s%%' %(area_code.split(',')[-1] if area_code!='' else ''), 'industry_code': '%s%%' %(industry_code.split(',')[-1] if industry_code!='' else '') } text_sql = "select t.tyshxydm,t.zzjgdm,t.dwxxmc,t.fddbr,t.dwszdz,t.hy from v_company t where t.dwxxmc like :kewword and t.hyfldm like :industry_code and t.dwszdqhdm like :area_code order by hy asc" rows = db_session.execute(text_sql, params).fetchall() def excelFile(rows): yield '统一社会信用代码,组织机构代码,单位详细名称,法定代表人(负责人),单位注册地址,行业\n' for row in rows: yield ','.join([row.tyshxydm if row.tyshxydm else '',row.zzjgdm if row.zzjgdm else '',row.dwxxmc if row.dwxxmc else '',row.fddbr if row.fddbr else '',row.dwszdz if row.dwszdz else '',row.hy if row.hy else ''])+'\n' filename = '企业查询结果导出.csv' response = Response(excelFile(rows), mimetype='text/csv') response.headers["Content-Disposition"] = "attachment; filename={}".format(filename) return response
Become a Linux Programmer