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