mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-09-21 21:06:39 +08:00
优化:字典选择组件支持多选
This commit is contained in:
parent
594c847523
commit
ff03f07b3f
@ -1,9 +1,11 @@
|
||||
package net.lab1024.sa.admin.module.business.goods.domain.form;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.lab1024.sa.admin.module.business.goods.constant.GoodsStatusEnum;
|
||||
import net.lab1024.sa.base.common.domain.PageParam;
|
||||
import net.lab1024.sa.base.common.json.deserializer.DictValueVoDeserializer;
|
||||
import net.lab1024.sa.base.common.swagger.SchemaEnum;
|
||||
import net.lab1024.sa.base.common.validator.enumeration.CheckEnum;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
@ -32,6 +34,7 @@ public class GoodsQueryForm extends PageParam {
|
||||
private Integer goodsStatus;
|
||||
|
||||
@Schema(description = "产地")
|
||||
@JsonDeserialize(using = DictValueVoDeserializer.class)
|
||||
private String place;
|
||||
|
||||
@Schema(description = "上架状态")
|
||||
|
@ -199,7 +199,7 @@ public class GoodsService {
|
||||
GoodsExcelVO.builder()
|
||||
.goodsStatus(SmartEnumUtil.getEnumDescByValue(e.getGoodsStatus(), GoodsStatusEnum.class))
|
||||
.categoryName(categoryQueryService.queryCategoryName(e.getCategoryId()))
|
||||
.place(dictCacheService.selectValueNameByValueCode(e.getPlace()))
|
||||
.place(Arrays.stream(e.getPlace().split(",")).map(code -> dictCacheService.selectValueNameByValueCode(code)).collect(Collectors.joining(",")))
|
||||
.price(e.getPrice())
|
||||
.goodsName(e.getGoodsName())
|
||||
.remark(e.getRemark())
|
||||
|
@ -18,7 +18,7 @@
|
||||
INSTR(goods_name,#{query.searchWord})
|
||||
</if>
|
||||
<if test="query.place != null">
|
||||
AND place = #{query.place}
|
||||
AND INSTR(place,#{query.place})
|
||||
</if>
|
||||
<if test="query.goodsStatus != null">
|
||||
AND goods_status = #{query.goodsStatus}
|
||||
|
@ -28,19 +28,19 @@ public class DictValueVoDeserializer extends JsonDeserializer<String> {
|
||||
|
||||
@Override
|
||||
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
|
||||
List<DictValueVO> list = new ArrayList<>();
|
||||
List<String> list = new ArrayList<>();
|
||||
ObjectCodec objectCodec = jsonParser.getCodec();
|
||||
JsonNode listOrObjectNode = objectCodec.readTree(jsonParser);
|
||||
String deserialize = "";
|
||||
try {
|
||||
if (listOrObjectNode.isArray()) {
|
||||
for (JsonNode node : listOrObjectNode) {
|
||||
list.add(objectCodec.treeToValue(node, DictValueVO.class));
|
||||
list.add(node.asText());
|
||||
}
|
||||
} else {
|
||||
list.add(objectCodec.treeToValue(listOrObjectNode, DictValueVO.class));
|
||||
list.add(listOrObjectNode.asText());
|
||||
}
|
||||
deserialize = list.stream().map(DictValueVO::getValueCode).collect(Collectors.joining(","));
|
||||
deserialize = String.join(",", list);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
deserialize = listOrObjectNode.asText();
|
||||
|
@ -64,24 +64,6 @@
|
||||
dictValueList.value = res.data;
|
||||
}
|
||||
|
||||
const values = computed(() => {
|
||||
if (!props.value) {
|
||||
return [];
|
||||
}
|
||||
if (!Array.isArray(props.value)) {
|
||||
console.error('valueList is not array!!!');
|
||||
return [];
|
||||
}
|
||||
let res = [];
|
||||
if (props.value && props.value.length > 0) {
|
||||
props.value.forEach((element) => {
|
||||
res.push(element.valueCode);
|
||||
});
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
});
|
||||
|
||||
onMounted(queryDict);
|
||||
|
||||
// -------------------------- 选中 相关、事件 --------------------------
|
||||
@ -96,21 +78,16 @@
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
function onChange(value) {
|
||||
let selected = [];
|
||||
if (!value) {
|
||||
emit('update:value', selected);
|
||||
emit('change', selected);
|
||||
return selected;
|
||||
emit('update:value', []);
|
||||
emit('change', []);
|
||||
}
|
||||
if (Array.isArray(props.value)) {
|
||||
let valueList = dictValueList.value.filter((e) => value.includes(e.valueCode));
|
||||
valueList = valueList.map((e) => e.valueCode);
|
||||
emit('update:value', valueList);
|
||||
emit('change', valueList);
|
||||
if (Array.isArray(value)) {
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
} else {
|
||||
let findValue = dictValueList.value.find((e) => e.valueCode === value);
|
||||
emit('update:value', findValue.valueCode);
|
||||
emit('change', findValue.valueCode);
|
||||
emit('update:value', [value]);
|
||||
emit('change', [value]);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -20,7 +20,7 @@
|
||||
<SmartEnumSelect enum-name="GOODS_STATUS_ENUM" v-model:value="form.goodsStatus" />
|
||||
</a-form-item>
|
||||
<a-form-item label="产地" name="place">
|
||||
<DictSelect key-code="GODOS_PLACE" v-model:value="form.place" />
|
||||
<DictSelect width="100%" key-code="GODOS_PLACE" v-model:value="form.place" mode="tags" />
|
||||
</a-form-item>
|
||||
<a-form-item label="上架状态" name="shelvesFlag">
|
||||
<a-radio-group v-model:value="form.shelvesFlag">
|
||||
@ -80,7 +80,7 @@
|
||||
//商品状态
|
||||
goodsStatus: GOODS_STATUS_ENUM.APPOINTMENT.value,
|
||||
//产地
|
||||
place: undefined,
|
||||
place: [],
|
||||
//商品价格
|
||||
price: undefined,
|
||||
//上架状态
|
||||
@ -107,9 +107,8 @@
|
||||
Object.assign(form, rowData);
|
||||
}
|
||||
if (form.place && form.place.length > 0) {
|
||||
form.place = form.place[0].valueCode;
|
||||
form.place = form.place.map((e) => e.valueCode);
|
||||
}
|
||||
console.log(form);
|
||||
visible.value = true;
|
||||
nextTick(() => {
|
||||
formRef.value.clearValidate();
|
||||
@ -127,14 +126,10 @@
|
||||
.then(async () => {
|
||||
SmartLoading.show();
|
||||
try {
|
||||
let params = _.cloneDeep(form);
|
||||
if (params.place && Array.isArray(params.place) && params.place.length > 0) {
|
||||
params.place = params.place[0].valueCode;
|
||||
}
|
||||
if (form.goodsId) {
|
||||
await goodsApi.updateGoods(params);
|
||||
await goodsApi.updateGoods(form);
|
||||
} else {
|
||||
await goodsApi.addGoods(params);
|
||||
await goodsApi.addGoods(form);
|
||||
}
|
||||
message.success(`${form.goodsId ? '修改' : '添加'}成功`);
|
||||
onClose();
|
||||
|
@ -109,7 +109,7 @@
|
||||
>
|
||||
<template #bodyCell="{ text, record, column }">
|
||||
<template v-if="column.dataIndex === 'place'">
|
||||
<span>{{ text && text.length > 0 ? text[0].valueName : '' }}</span>
|
||||
<span>{{ text && text.length > 0 ? text.map((e) => e.valueName).join(',') : '' }}</span>
|
||||
</template>
|
||||
<template v-if="column.dataIndex === 'goodsStatus'">
|
||||
<span>{{ $smartEnumPlugin.getDescByValue('GOODS_STATUS_ENUM', text) }}</span>
|
||||
|
Loading…
Reference in New Issue
Block a user