perf: 工作汇报可留空汇报对象

This commit is contained in:
kuaifan 2023-01-31 14:07:14 +08:00
parent 88362cb1f9
commit b7ac923d36
2 changed files with 32 additions and 20 deletions

View File

@ -119,13 +119,13 @@ class ReportController extends AbstractController
* @apiGroup report
* @apiName store
*
* @apiParam {Number} [id] 汇报ID
* @apiParam {String} [sign] 唯一签名,通过[api/report/template]接口返回
* @apiParam {String} [title] 汇报标题
* @apiParam {Array} [type] 汇报类型weekly:周报daily:日报
* @apiParam {Number} [content] 内容
* @apiParam {Number} [receive] 汇报对象
* @apiParam {Number} [offset] 偏移量
* @apiParam {Number} id 汇报ID0为新建
* @apiParam {String} [sign] 唯一签名,通过[api/report/template]接口返回
* @apiParam {String} title 汇报标题
* @apiParam {Array} type 汇报类型weekly:周报daily:日报
* @apiParam {Number} content 内容
* @apiParam {Number} [receive] 汇报对象
* @apiParam {Number} offset 时间偏移量
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
@ -133,8 +133,11 @@ class ReportController extends AbstractController
*/
public function store(): array
{
$user = User::auth();
//
$input = [
"id" => Base::getPostValue("id", 0),
"sign" => Base::getPostValue("sign"),
"title" => Base::getPostValue("title"),
"type" => Base::getPostValue("type"),
"content" => Base::getPostValue("content"),
@ -147,7 +150,6 @@ class ReportController extends AbstractController
'title' => 'required',
'type' => ['required', Rule::in([Report::WEEKLY, Report::DAILY])],
'content' => 'required',
'receive' => 'required',
'offset' => ['numeric', 'max:0'],
], [
'id.numeric' => 'ID只能是数字',
@ -155,14 +157,12 @@ class ReportController extends AbstractController
'type.required' => '请选择汇报类型',
'type.in' => '汇报类型错误',
'content.required' => '请填写汇报内容',
'receive.required' => '请选择接收人',
'offset.numeric' => '工作汇报周期格式错误,只能是数字',
'offset.max' => '只能提交当天/本周或者之前的的工作汇报',
]);
if ($validator->fails())
return Base::retError($validator->errors()->first());
$user = User::auth();
// 接收人
if (is_array($input["receive"])) {
// 删除当前登录人
@ -207,11 +207,11 @@ class ReportController extends AbstractController
"content" => htmlspecialchars($input["content"]),
]);
}
$report->save();
if (!empty($input["receive_content"])) {
// 删除关联
$report->Receives()->delete();
// 删除关联
$report->Receives()->delete();
if ($input["receive_content"]) {
// 保存接收人
$report->Receives()->createMany($input["receive_content"]);
}

View File

@ -36,7 +36,9 @@
:placeholder="$L('选择接收人')"
:transfer="false"/>
<a class="report-user-link" href="javascript:void(0);" @click="getLastSubmitter">
<Icon type="ios-share-outline" />{{ $L("使用我上次的汇报对象") }}
<Icon v-if="receiveLoad > 0" type="ios-loading" class="icon-loading"/>
<Icon v-else type="ios-share-outline" />
{{ $L("使用我上次的汇报对象") }}
</a>
</div>
</FormItem>
@ -44,7 +46,7 @@
<TEditor v-model="reportData.content" height="100%"/>
</FormItem>
<FormItem class="report-foot">
<Button type="primary" @click="handleSubmit" class="report-bottom">{{$L(id > 0 ? '修改' : '提交')}}</Button>
<Button type="primary" @click="handleSubmit" :loading="loadIng > 0" class="report-bottom">{{$L(id > 0 ? '修改' : '提交')}}</Button>
</FormItem>
</Form>
</template>
@ -66,6 +68,9 @@ export default {
},
data() {
return {
loadIng: 0,
receiveLoad: 0,
reportData: {
sign: "",
title: "",
@ -99,10 +104,6 @@ export default {
},
methods: {
handleSubmit() {
if (this.reportData.receive.length === 0) {
$A.messageError(this.$L("请选择接收人"));
return false;
}
if (this.id === 0 && this.reportData.id > 0) {
$A.modalConfirm({
title: '覆盖提交',
@ -117,6 +118,7 @@ export default {
},
doSubmit() {
this.loadIng++;
this.$store.dispatch("call", {
url: 'report/store',
data: this.reportData,
@ -133,10 +135,13 @@ export default {
}).catch(({msg}) => {
// msg
$A.messageError(msg);
}).finally(_ => {
this.loadIng--;
});
},
getTemplate() {
this.loadIng++;
this.$store.dispatch("call", {
url: 'report/template',
data: {
@ -164,6 +169,8 @@ export default {
}).catch(({msg}) => {
// msg
$A.messageError(msg);
}).finally(_ => {
this.loadIng--;
});
},
@ -216,12 +223,17 @@ export default {
//
getLastSubmitter() {
setTimeout(_ => {
this.receiveLoad++;
}, 300)
this.$store.dispatch("call", {
url: 'report/last_submitter',
}).then(({data}) => {
this.reportData.receive = data;
}).catch(({msg}) => {
$A.messageError(msg);
}).finally(_ => {
this.receiveLoad--;
});
},