feat: 工作报告支持批量标记已读

This commit is contained in:
kuaifan 2022-09-18 19:18:54 +08:00
parent 6c81f828bd
commit c7b76e1009
4 changed files with 146 additions and 15 deletions

View File

@ -392,6 +392,48 @@ class ReportController extends AbstractController
return Base::retSuccess("success", $one);
}
/**
* @api {get} api/report/mark 05. 标记已读/未读
*
* @apiVersion 1.0.0
* @apiGroup report
* @apiName mark
*
* @apiParam {Number} id 报告id
* @apiParam {Number} action 操作
* - read: 标记已读(默认)
* - unread: 标记未读
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function mark(): array
{
$user = User::auth();
//
$id = Request::input('id');
$action = Request::input('action');
//
if (is_array($id)) {
if (count(Base::arrayRetainInt($id)) > 100) {
return Base::retError("最多只能操作100条数据");
}
$builder = Report::whereIn("id", Base::arrayRetainInt($id));
} else {
$builder = Report::whereId(intval($id));
}
$builder ->chunkById(100, function ($list) use ($action, $user) {
/** @var Report $item */
foreach ($list as $item) {
$item->receivesUser()->updateExistingPivot($user->userid, [
"read" => $action === 'unread' ? 0 : 1,
]);
}
});
return Base::retSuccess("操作成功");
}
/**
* @api {get} api/report/last_submitter 06. 获取最后一次提交的接收人
*

View File

@ -5,7 +5,7 @@
<ReportMy ref="report" v-if="reportTabs === 'my'" @on-view="onView" @on-edit="onEditReport"/>
</TabPane>
<TabPane :label="tabRebder(reportUnreadNumber)" name="receive">
<ReportReceive v-if="reportTabs === 'receive'" @on-view="onView"/>
<ReportReceive v-if="reportTabs === 'receive'" @on-view="onView" @on-read="onRead"/>
</TabPane>
</Tabs>
<DrawerOverlay
@ -114,6 +114,10 @@ export default {
}
},
onRead() {
this.$emit("on-read", 0)
},
onEditReport(id) {
if (this.$Electron) {
let config = {

View File

@ -56,26 +56,36 @@
:data="lists"
:loading="loadIng > 0"
:no-data-text="$L(noDataText)"
@on-selection-change="selectChange"
stripe/>
<Page
:total="listTotal"
:current="listPage"
:page-size="listPageSize"
:disabled="loadIng > 0"
:simple="windowSmall"
:page-size-opts="[10,20,30,50,100]"
show-elevator
show-sizer
show-total
@on-change="setPage"
@on-page-size-change="setPageSize"/>
<div class="table-attach">
<!-- 选择执行 -->
<div class="select-box">
<Select v-model="selectAction" :disabled="selectIds.length==0" @on-change="groupSelect=true" :placeholder="$L('请选择')" transfer>
<Option value="read">{{ $L('标记已读') }}</Option>
<Option value="unread">{{ $L('标记未读') }}</Option>
</Select>
<Button :loading="loadIng > 0" type="primary" @click="selectClick" :disabled="selectAction=='' || selectIds.length==0">{{$L('执行')}}</Button>
</div>
<!-- 分页 -->
<Page
:total="listTotal"
:current="listPage"
:page-size="listPageSize"
:disabled="loadIng > 0"
:simple="windowSmall"
:page-size-opts="[10,20,30,50,100]"
show-elevator
show-sizer
show-total
@on-change="setPage"
@on-page-size-change="setPageSize"/>
</div>
</div>
</div>
</template>
<script>
import {mapState} from "vuex";
export default {
name: "ReportReceive",
data() {
@ -91,6 +101,9 @@ export default {
keys: {},
keyIs: false,
selectIds: [],
selectAction: '',
reportTypeList: [
{value: "", label: this.$L('全部')},
{value: "weekly", label: this.$L('周报')},
@ -112,6 +125,10 @@ export default {
methods: {
initLanguage() {
this.columns = [{
type: 'selection',
width: 50,
align: 'right'
}, {
title: this.$L("标题"),
key: 'title',
sortable: true,
@ -222,6 +239,53 @@ export default {
this.getLists();
}
},
selectChange(items) {
this.selectIds = items.map(({id}) => id);
},
selectClick() {
if (this.selectIds.length === 0) {
$A.messageWarning('请选择线路');
return;
}
switch (this.selectAction) {
case 'read':
case 'unread':
this.readReport(this.selectIds, this.selectAction)
break;
default:
$A.messageWarning('请选择执行方式');
break;
}
},
readReport(id, action) {
const label = action === 'read' ? '标记已读' : '标记未读'
$A.modalConfirm({
content: `你确定要【${label}】吗?`,
cancelText: '取消',
okText: '确定',
loading: true,
onOk: () => {
return new Promise((resolve, reject) => {
this.$store.dispatch("call", {
url: 'report/mark',
data: {
id,
action,
}
}).then(({msg}) => {
resolve(msg);
this.getLists();
this.$emit("on-read")
}).catch(({msg}) => {
reject(msg);
});
})
}
});
},
}
}
</script>

View File

@ -528,6 +528,27 @@ body {
text-align: center;
margin-top: 20px;
}
.table-attach {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
margin-top: 20px;
.select-box {
margin-right: 12px;
.ivu-select {
width: auto;
max-width: 200px;
margin-right: 3px;
}
}
.ivu-page {
padding: 0;
margin-top: 0;
margin-left: 12px;
}
}
}
.page-container {