Merge branch 'master' of gitee.com:yudaocode/yudao-ui-admin-vue3

pull/495/head
preschool 2024-08-14 15:32:45 +08:00
commit c40ca1333d
6 changed files with 107 additions and 32 deletions

View File

@ -24,20 +24,6 @@ export interface PropertyValueVO {
remark?: string
}
/**
*
*/
export interface PropertyValueDetailVO {
/** 属性项的编号 */
propertyId: number // 属性的编号
/** 属性的名称 */
propertyName: string
/** 属性值的编号 */
valueId: number
/** 属性值的名称 */
valueName: string
}
// ------------------------ 属性项 -------------------
// 创建属性项
@ -65,6 +51,11 @@ export const getPropertyPage = (params: PageParam) => {
return request.get({ url: '/product/property/page', params })
}
// 获得属性项精简列表
export const getPropertySimpleList = (): Promise<PropertyVO[]> => {
return request.get({ url: '/product/property/simple-list' })
}
// ------------------------ 属性值 -------------------
// 获得属性值分页
@ -91,3 +82,8 @@ export const updatePropertyValue = (data: PropertyValueVO) => {
export const deletePropertyValue = (id: number) => {
return request.delete({ url: `/product/property/value/delete?id=${id}` })
}
// 获得属性值精简列表
export const getPropertyValueSimpleList = (propertyId: number): Promise<PropertyValueVO[]> => {
return request.get({ url: '/product/property/value/simple-list', params: { propertyId } })
}

View File

@ -3,7 +3,7 @@ import { defineComponent, PropType, computed } from 'vue'
import { isHexColor } from '@/utils/color'
import { ElTag } from 'element-plus'
import { DictDataType, getDictOptions } from '@/utils/dict'
import { isArray, isString, isNumber } from '@/utils/is'
import { isArray, isString, isNumber, isBoolean } from '@/utils/is'
export default defineComponent({
name: 'DictTag',
@ -29,8 +29,8 @@ export default defineComponent({
},
setup(props) {
const valueArr: any = computed(() => {
// 1.Number
if (isNumber(props.value)) {
// 1. Number Boolean
if (isNumber(props.value) || isBoolean(props.value)) {
return [String(props.value)]
}
// 2. -> props.sepSymbol
@ -57,7 +57,7 @@ export default defineComponent({
<div
class="dict-tag"
style={{
display: 'flex',
display: 'inline-flex',
gap: props.gutter,
justifyContent: 'center',
alignItems: 'center'

View File

@ -24,7 +24,7 @@
>
<template #default="{ row }">
<span style="font-weight: bold; color: #40aaff">
{{ row.properties[index]?.valueName }}
{{ row.properties?.[index]?.valueName }}
</span>
</template>
</el-table-column>
@ -168,7 +168,7 @@
>
<template #default="{ row }">
<span style="font-weight: bold; color: #40aaff">
{{ row.properties[index]?.valueName }}
{{ row.properties?.[index]?.valueName }}
</span>
</template>
</el-table-column>
@ -248,7 +248,7 @@
>
<template #default="{ row }">
<span style="font-weight: bold; color: #40aaff">
{{ row.properties[index]?.valueName }}
{{ row.properties?.[index]?.valueName }}
</span>
</template>
</el-table-column>

View File

@ -18,16 +18,28 @@
>
{{ value.name }}
</el-tag>
<el-input
v-show="inputVisible(index)"
<el-select
:id="`input${index}`"
:ref="setInputRef"
v-show="inputVisible(index)"
v-model="inputValue"
class="!w-20"
filterable
allow-create
default-first-option
:reserve-keyword="false"
size="small"
class="!w-30"
@blur="handleInputConfirm(index, item.id)"
@keyup.enter="handleInputConfirm(index, item.id)"
@change="handleInputConfirm(index, item.id)"
>
<el-option
v-for="item2 in attributeOptions"
:key="item2.id"
:label="item2.name"
:value="item2.name"
/>
</el-select>
<el-button
v-show="!inputVisible(index)"
class="button-new-tag ml-1"
@ -42,7 +54,6 @@
</template>
<script lang="ts" setup>
import { ElInput } from 'element-plus'
import * as PropertyApi from '@/api/mall/product/property'
import { PropertyAndValues } from '@/views/mall/product/spu/components'
import { propTypes } from '@/utils/propTypes'
@ -68,6 +79,7 @@ const setInputRef = (el: any) => {
}
}
const attributeList = ref<PropertyAndValues[]>([]) //
const attributeOptions = ref([] as PropertyApi.PropertyValueVO[]) //
const props = defineProps({
propertyList: {
type: Array,
@ -100,15 +112,25 @@ const handleCloseProperty = (index: number) => {
}
/** 显示输入框并获取焦点 */
const showInput = async (index) => {
const showInput = async (index: number) => {
attributeIndex.value = index
inputRef.value[index].focus()
//
await getAttributeOptions(attributeList.value[index].id)
}
/** 输入框失去焦点或点击回车时触发 */
const emit = defineEmits(['success']) // success
const handleInputConfirm = async (index: number, propertyId: number) => {
if (inputValue.value) {
//
// TODO @
if (attributeList.value[index].values.find((item) => item.name === inputValue.value)) {
message.warning('已存在相同属性值,请重试')
attributeIndex.value = null
inputValue.value = ''
return
}
//
try {
const id = await PropertyApi.createPropertyValue({ propertyId, name: inputValue.value })
@ -122,4 +144,9 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
attributeIndex.value = null
inputValue.value = ''
}
/** 获取商品属性下拉选项 */
const getAttributeOptions = async (propertyId: number) => {
attributeOptions.value = await PropertyApi.getPropertyValueSimpleList(propertyId)
}
</script>

View File

@ -10,7 +10,22 @@
@keydown.enter.prevent="submitForm"
>
<el-form-item label="属性名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入名称" />
<el-select
v-model="formData.name"
filterable
allow-create
default-first-option
:reserve-keyword="false"
placeholder="请选择属性名称。如果不存在,可手动输入选择"
class="!w-360px"
>
<el-option
v-for="item in attributeOptions"
:key="item.id"
:label="item.name"
:value="item.name"
/>
</el-select>
</el-form-item>
</el-form>
<template #footer>
@ -37,6 +52,7 @@ const formRules = reactive({
})
const formRef = ref() // Ref
const attributeList = ref([]) //
const attributeOptions = ref([] as PropertyApi.PropertyVO[]) //
const props = defineProps({
propertyList: {
type: Array,
@ -60,11 +76,21 @@ watch(
const open = async () => {
dialogVisible.value = true
resetForm()
//
await getAttributeOptions()
}
defineExpose({ open }) // open
/** 提交表单 */
const submitForm = async () => {
//
for (const attrItem of attributeList.value) {
if (attrItem.name === formData.value.name) {
return message.error('该属性已存在,请勿重复添加')
}
}
//
//
if (!formRef) return
const valid = await formRef.value.validate()
@ -80,6 +106,15 @@ const submitForm = async () => {
...formData.value,
values: []
})
// emit
for (const element of attributeOptions.value) {
if (element.name === formData.value.name) {
message.success(t('common.createSuccess'))
dialogVisible.value = false
return
}
}
//
message.success(t('common.createSuccess'))
dialogVisible.value = false
} finally {
@ -94,4 +129,14 @@ const resetForm = () => {
}
formRef.value?.resetFields()
}
/** 获取商品属性下拉选项 */
const getAttributeOptions = async () => {
formLoading.value = true
try {
attributeOptions.value = await PropertyApi.getPropertySimpleList()
} finally {
formLoading.value = false
}
}
</script>

View File

@ -1,6 +1,13 @@
<!-- 商品发布 - 库存价格 -->
<template>
<el-form ref="formRef" :disabled="isDetail" :model="formData" :rules="rules" label-width="120px">
<el-form
ref="formRef"
:disabled="isDetail"
:model="formData"
:rules="rules"
label-width="120px"
v-loading="formLoading"
>
<el-form-item label="分销类型" props="subCommissionType">
<el-radio-group
v-model="formData.subCommissionType"
@ -94,7 +101,7 @@ const ruleConfig: RuleConfig[] = [
]
const message = useMessage() //
const formLoading = ref(false)
const props = defineProps({
propFormData: {
type: Object as PropType<Spu>,