导出名称修改

This commit is contained in:
邓皓元 2019-08-06 11:52:25 +08:00
parent 1663548147
commit 3ee06ecfce
6 changed files with 108 additions and 82 deletions

View File

@ -154,11 +154,11 @@ abstract class AbstractExport implements WithEvents, WithTitle, ShouldAutoSize
$title = $this->tag(); $title = $this->tag();
if (($conditions = $this->conditions) && $conditions['starttime'] && $conditions['endtime']) { if (($conditions = $this->conditions) && $conditions['starttime'] && $conditions['endtime']) {
$title .= Carbon::parse($conditions['starttime'])->format('Ymd') . '-' . Carbon::parse($conditions['endtime'])->format('Ymd'); $title = Carbon::parse($conditions['starttime'])->format('Ymd') . '-' . Carbon::parse($conditions['endtime'])->format('Ymd') . ' ' . $title;
} }
if (($conditions = $this->conditions) && $conditions['month']) { if (($conditions = $this->conditions) && $conditions['month']) {
$title .= Carbon::parse($conditions['month'])->format('Ym'); $title = Carbon::parse($conditions['month'])->format('Ym') . ' ' . $title;
} }
return $title ?? '列表'; return $title ?? '列表';
@ -171,7 +171,7 @@ abstract class AbstractExport implements WithEvents, WithTitle, ShouldAutoSize
*/ */
protected function sn(): string protected function sn(): string
{ {
return date('YmdHis') .sprintf('%04d', explode('.', microtime(true))[1]) . sprintf('%02d', rand(0, 99)); return date('YmdHis') . sprintf('%04d', explode('.', microtime(true))[1]) . sprintf('%02d', rand(0, 99));
} }
/** /**
@ -181,9 +181,9 @@ abstract class AbstractExport implements WithEvents, WithTitle, ShouldAutoSize
*/ */
protected function filename(): string protected function filename(): string
{ {
$title = $this->tag(); $title = $this->title();
$filename = $title . date('YmdHis'); $filename = $title . ' ' . date('YmdHis');
return "export/{$filename}.xlsx"; return "export/{$filename}.xlsx";
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace App\Domains\Export\Services; namespace App\Domains\Export\Services;
use App\Dicts; use App\Dicts;
@ -8,6 +9,7 @@ use Dipper\Excel\Facades\Excel;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use App\Domains\Export\Repositories\ExportRepository; use App\Domains\Export\Repositories\ExportRepository;
use function GuzzleHttp\json_encode;
class ExportService extends Service class ExportService extends Service
{ {
@ -50,19 +52,20 @@ class ExportService extends Service
$url = $item->status === 3 ? Storage::disk($item->disk)->url($item->filename) : ''; $url = $item->status === 3 ? Storage::disk($item->disk)->url($item->filename) : '';
$conditions = json_encode(array_except($item->conditions ?? [], ['page', 'limit', 'orderBy', 'sortedBy']), 256); $conditions = array_except($item->conditions ?? [], ['page', 'limit', 'orderBy', 'sortedBy']);
return [ return [
'id' => $item->id, 'id' => $item->id,
'tag' => $item->tag, 'tag' => $item->tag,
'filename' => basename($url),
'filesize' => human_filesize($item->filesize), 'filesize' => human_filesize($item->filesize),
'dateline' => !$item->conditions['starttime'] ? '所有' : $item->conditions['starttime'] . ' 至 ' . $item->conditions['endtime'], 'dateline' => !$item->conditions['starttime'] ? '所有' : $item->conditions['starttime'] . ' 至 ' . $item->conditions['endtime'],
'conditions' => $conditions, 'conditions' => json_encode($conditions, JSON_PRETTY_PRINT),
'status' => $item->status, 'status' => $item->status,
'status_name' => $status[$item->status], 'status_name' => $status[$item->status],
'url' => $url, 'url' => $url,
'created_at' => (string)$item->created_at, 'created_at' => (string) $item->created_at,
'updated_at' => (string)$item->updated_at, 'updated_at' => (string) $item->updated_at,
]; ];
}); });

View File

@ -81,7 +81,7 @@ class CompanyReportDetailExport extends AbstractExport implements FromQuery, Wit
foreach ($rows as $item) { foreach ($rows as $item) {
$company = CompanyService::load($item->company_id); $company = CompanyService::load($item->company_id);
$package = PackageService::load($item->package_id); $package = PackageService::load($item->package_id);
$month_price = sprintf('%.02f', $item->unit_price/100/$package['service_months']); $month_price = sprintf('%.02f', $item->unit_price / 100 / $package['service_months']);
$array[] = [ $array[] = [
$item['sim'], $item['sim'],
@ -118,7 +118,7 @@ class CompanyReportDetailExport extends AbstractExport implements FromQuery, Wit
$title = $this->tag(); $title = $this->tag();
if (($conditions = $this->conditions) && $conditions['month']) { if (($conditions = $this->conditions) && $conditions['month']) {
$title .= Carbon::parse($conditions['month'])->format('Ym'); $title = Carbon::parse($conditions['month'])->format('Ym') . ' ' . $title;
} }
return $title ?? '列表'; return $title ?? '列表';

View File

@ -77,7 +77,7 @@ class CompanyReportExport extends AbstractExport implements FromCollection, With
$title = $this->tag(); $title = $this->tag();
if (($conditions = $this->conditions) && $conditions['month']) { if (($conditions = $this->conditions) && $conditions['month']) {
$title .= Carbon::parse($conditions['month'])->format('Ym'); $title = Carbon::parse($conditions['month'])->format('Ym') . ' ' . $title;
} }
return $title ?? '列表'; return $title ?? '列表';

View File

@ -1,9 +1,9 @@
export default { export default {
name: 'Exports', name: "Exports",
data() { data() {
return { return {
params: { params: {
request_param: '' request_param: ""
}, },
other: { other: {
time: [], time: [],
@ -16,84 +16,100 @@ export default {
selection: [], // 复选框选中项 selection: [], // 复选框选中项
table_titles: [ table_titles: [
{ {
type: 'selection', type: "selection",
width: 60, width: 60,
align: 'center' align: "center"
}, },
{ {
title: '序号', title: "序号",
key: '', key: "",
width: 80, width: 80,
render: (h, { row, column, index }) => { render: (h, { row, column, index }) => {
return h('span', index + 1); return h("span", index + 1);
} }
}, },
{ {
title: '类型', title: "文件名称",
key: 'tag', key: "filename",
render: (h, { row, column, index }) => {
return h(
"Tooltip",
{ props: { content: row.conditions, "max-width": 300 } },
row.filename
);
}
},
{
title: "类型",
key: "tag",
width: 150 width: 150
}, },
{ {
title: '查询条件', title: "文件大小",
key: '', key: "filesize",
render: (h, { row, column, index }) => {
return h('pre', row.conditions);
}
},
{
title: '文件大小',
key: 'filesize',
width: 120 width: 120
}, },
{ {
title: '状态', title: "状态",
key: 'status_name', key: "status_name",
width: 120 width: 120
}, },
{ {
title: '创建时间', title: "创建时间",
key: 'created_at', key: "created_at",
width: 170 width: 170
}, },
{ {
title: '操作', title: "操作",
key: 'action', key: "action",
render: (h, { row, column, index }) => { render: (h, { row, column, index }) => {
let html = []; let html = [];
if (row.status === 3) { if (row.status === 3) {
html.push(h('Button', { html.push(
props: { h(
type: 'success', "Button",
size: 'small', {
disabled: false, props: {
icon: 'md-trash', type: "success",
target: '_blank', size: "small",
to: row.url disabled: false,
}, icon: "md-trash",
class: ['btn'] target: "_blank",
}, '下载')); to: row.url
},
class: ["btn"]
},
"下载"
)
);
} }
if (this.haveJurisdiction('destroy')) { if (this.haveJurisdiction("destroy")) {
html.push(h('Button', { html.push(
props: { h(
type: 'error', "Button",
size: 'small', {
disabled: false, props: {
icon: 'md-trash' type: "error",
}, size: "small",
class: ['btn'], disabled: false,
on: { icon: "md-trash"
click: () => { },
this.destroy({ ids: row.id }); class: ["btn"],
} on: {
} click: () => {
}, '删除')); this.destroy({ ids: row.id });
}
}
},
"删除"
)
);
} }
if (html.length) { if (html.length) {
return h('div', html); return h("div", html);
} }
} }
} }
@ -113,16 +129,19 @@ export default {
this.scrollTop(); this.scrollTop();
let data = this.searchDataHandle(this.params, { page }, this.other); let data = this.searchDataHandle(this.params, { page }, this.other);
this.isShowLoading(true); this.isShowLoading(true);
service.get('api/exports', { params: data }).then(res => { service
this.isShowLoading(false); .get("api/exports", { params: data })
if (res.code == 0) { .then(res => {
let result = res.data; this.isShowLoading(false);
result.data = this.tableCheckboxHandle(result.data, this.selection); if (res.code == 0) {
this.list_data = result; let result = res.data;
} result.data = this.tableCheckboxHandle(result.data, this.selection);
}).catch(err => { this.list_data = result;
this.isShowLoading(false); }
}); })
.catch(err => {
this.isShowLoading(false);
});
}, },
/** /**
@ -142,9 +161,9 @@ export default {
let arry = this.selection.map(item => { let arry = this.selection.map(item => {
return item.id; return item.id;
}); });
this.destroy({ ids: arry.join(',') }); this.destroy({ ids: arry.join(",") });
} else { } else {
this.$Message.info('请勾选要删除的项'); this.$Message.info("请勾选要删除的项");
} }
}, },
@ -155,13 +174,13 @@ export default {
*/ */
destroy(data) { destroy(data) {
this.$Modal.confirm({ this.$Modal.confirm({
title: '提示', title: "提示",
content: '确认执行删除操作?', content: "确认执行删除操作?",
onOk: () => { onOk: () => {
service.post('api/exports/destroy', data).then(res => { service.post("api/exports/destroy", data).then(res => {
if (res.code == 0) { if (res.code == 0) {
// 当有勾选项删除操作的地方为每行的按钮将复选框勾选项去除此id // 当有勾选项删除操作的地方为每行的按钮将复选框勾选项去除此id
const ids = data.ids.toString().split(','); const ids = data.ids.toString().split(",");
if (ids.length == 1) { if (ids.length == 1) {
for (let i = 0, len = this.selection.length; i < len; i++) { for (let i = 0, len = this.selection.length; i < len; i++) {
if (ids[0] == this.selection[i].id) { if (ids[0] == this.selection[i].id) {
@ -170,7 +189,7 @@ export default {
} }
} }
} }
this.$Message.success('删除成功'); this.$Message.success("删除成功");
this.request(); this.request();
} }
}); });
@ -187,7 +206,11 @@ export default {
let page = result.current_page; let page = result.current_page;
if (this.list_data.data.length == 1) { if (this.list_data.data.length == 1) {
page = this.returnPage(result.total, result.current_page, result.per_page); page = this.returnPage(
result.total,
result.current_page,
result.per_page
);
} }
this.index(page); this.index(page);
@ -195,7 +218,7 @@ export default {
resetSearch() { resetSearch() {
for (let k in this.params) { for (let k in this.params) {
this.params[k] = ''; this.params[k] = "";
} }
this.other.tag = null; this.other.tag = null;
this.other.time = []; this.other.time = [];

Binary file not shown.