Browse Source

修改 bug

master
王泽彦 8 months ago
parent
commit
06a70557bf
  1. 2
      admin/src/app/lang/zh-cn/venue.venue.json
  2. 54
      admin/src/app/views/venue/components/venue-edit.vue
  3. 2
      niucloud/app/adminapi/controller/venue/Venue.php
  4. 20
      niucloud/app/service/admin/dict/DictService.php
  5. 8
      niucloud/app/service/admin/venue/VenueService.php

2
admin/src/app/lang/zh-cn/venue.venue.json

@ -9,6 +9,8 @@
"availabilityStatusPlaceholder": "请输入场地可用状态",
"timeRangeType": "时间范围类型",
"timeRangeTypePlaceholder": "请输入场地可用时间范围类型",
"timeRange": "时间范围",
"allTimeAvailable": "全天可用提示",
"fixedTimeRanges": "时间范围",
"fixedTimeRangesPlaceholder": "请输入时间范围",
"createdAt": "创建时间",

54
admin/src/app/views/venue/components/venue-edit.vue

@ -217,7 +217,7 @@ const initialFormData = {
campus_id: '',
venue_name: '',
capacity: '',
availability_status: '1',
availability_status: '', //
time_range_type: '',
time_range_start: '',
time_range_end: '',
@ -483,31 +483,41 @@ const confirm = async (formEl: FormInstance | undefined) => {
//
let availability_statusList = ref([])
const availability_statusDictList = async () => {
availability_statusList.value = await (
await useDictionary('SiteStatus')
).data.dictionary
}
availability_statusDictList()
watch(
() => availability_statusList.value,
() => {
formData.availability_status = availability_statusList.value[0].value
}
)
let time_range_typeList = ref([])
const time_range_typeDictList = async () => {
time_range_typeList.value = await (
await useDictionary('ALLOTTED_TIME')
).data.dictionary
let dictLoaded = ref(false) //
const loadDictionaries = async () => {
if (dictLoaded.value) return //
try {
//
const [siteStatusRes, timeRangeRes] = await Promise.all([
useDictionary('SiteStatus'),
useDictionary('ALLOTTED_TIME')
])
availability_statusList.value = siteStatusRes.data.dictionary || []
time_range_typeList.value = timeRangeRes.data.dictionary || []
// formData
if (availability_statusList.value.length > 0 && !formData.availability_status) {
formData.availability_status = availability_statusList.value[0].value
}
time_range_typeDictList()
watch(
() => time_range_typeList.value,
() => {
if (time_range_typeList.value.length > 0 && !formData.time_range_type) {
formData.time_range_type = time_range_typeList.value[0].value
}
)
dictLoaded.value = true
} catch (error) {
console.error('加载字典数据失败:', error)
availability_statusList.value = []
time_range_typeList.value = []
}
}
//
loadDictionaries()
const campusIdList = ref([] as any[])
const setCampusIdList = async () => {

2
niucloud/app/adminapi/controller/venue/Venue.php

@ -62,6 +62,8 @@ class Venue extends BaseAdminController
["capacity", 0],
["availability_status", 0],
["time_range_type", ""],
["time_range_start", ""],
["time_range_end", ""],
["fixed_time_ranges", []],
]);

20
niucloud/app/service/admin/dict/DictService.php

@ -117,6 +117,26 @@ class DictService extends BaseAdminService
if($info['dictionary'] == null)
{
$info['dictionary'] = [];
} else if(is_string($info['dictionary'])) {
// 解析JSON字符串,处理可能的嵌套编码
$decoded = json_decode($info['dictionary'], true);
if (json_last_error() === JSON_ERROR_NONE) {
if (is_array($decoded)) {
$info['dictionary'] = $decoded;
} else if (is_string($decoded)) {
// 双重JSON编码的情况,再次解析
$double_decoded = json_decode($decoded, true);
if (json_last_error() === JSON_ERROR_NONE && is_array($double_decoded)) {
$info['dictionary'] = $double_decoded;
} else {
$info['dictionary'] = [];
}
} else {
$info['dictionary'] = [];
}
} else {
$info['dictionary'] = [];
}
}
return $info;
}

8
niucloud/app/service/admin/venue/VenueService.php

@ -57,7 +57,13 @@ class VenueService extends BaseAdminService
$info = $this->model->field($field)->where([['id', "=", $id]])->with(['campus'])->findOrEmpty()->toArray();
$info['availability_status'] = strval($info['availability_status']);
$info['time_range_type'] = strval($info['time_range_type']);
$info['fixed_time_ranges'] = json_decode($info['fixed_time_ranges'], true);
// 处理 fixed_time_ranges 字段的 JSON 解析,避免 null 值导致的错误
if ($info['fixed_time_ranges'] === null || $info['fixed_time_ranges'] === '') {
$info['fixed_time_ranges'] = [];
} else {
$decoded = json_decode($info['fixed_time_ranges'], true);
$info['fixed_time_ranges'] = (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) ? $decoded : [];
}
return $info;
}

Loading…
Cancel
Save