forked from opentiny/tiny-vue
feat(input): [input] add memorySpace props which can set max number of addMemory (#1188)
* feat(input): [input] add memorySpace props which can set max number of addMemory * feat(input): [input] add memorySpace props which can set max number of addMemory 2
This commit is contained in:
parent
642e31eee6
commit
c746f53e53
|
@ -5,6 +5,7 @@
|
||||||
v-model="input"
|
v-model="input"
|
||||||
name="textMemory"
|
name="textMemory"
|
||||||
placeholder="Please input"
|
placeholder="Please input"
|
||||||
|
:memory-space="3"
|
||||||
@change="addMemory"
|
@change="addMemory"
|
||||||
></tiny-input>
|
></tiny-input>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,4 +17,15 @@ test('[Input]method-addMemory', async ({ page }) => {
|
||||||
await input.fill('')
|
await input.fill('')
|
||||||
const box = await page.locator('.tiny-modal__body').getByText('1234')
|
const box = await page.locator('.tiny-modal__body').getByText('1234')
|
||||||
await expect(box).toBeVisible()
|
await expect(box).toBeVisible()
|
||||||
|
|
||||||
|
// memory-space = 3
|
||||||
|
await input.fill('2222')
|
||||||
|
await input.blur()
|
||||||
|
await input.fill('3333')
|
||||||
|
await input.blur()
|
||||||
|
await input.fill('4444')
|
||||||
|
await input.blur()
|
||||||
|
await input.fill('')
|
||||||
|
await input.click()
|
||||||
|
await expect(page.locator('.tiny-tall-storage .tiny-storage-item')).toHaveCount(3)
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
v-model="input"
|
v-model="input"
|
||||||
name="textMemory"
|
name="textMemory"
|
||||||
placeholder="Please input"
|
placeholder="Please input"
|
||||||
|
:memory-space="3"
|
||||||
@change="addMemory"
|
@change="addMemory"
|
||||||
></tiny-input>
|
></tiny-input>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -295,6 +295,16 @@ export default {
|
||||||
},
|
},
|
||||||
'demoId': 'native'
|
'demoId': 'native'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'name': 'memory-space',
|
||||||
|
'type': 'number',
|
||||||
|
'defaultValue': '5',
|
||||||
|
'desc': {
|
||||||
|
'zh-CN': '设置 addMemory 方法中,最大能保存条目的数量',
|
||||||
|
'en-US': 'Sets the maximum number of entries that can be saved in the addMemory method'
|
||||||
|
},
|
||||||
|
'demoId': 'method-addMemory'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'name': 'maxlength',
|
'name': 'maxlength',
|
||||||
'type': 'number',
|
'type': 'number',
|
||||||
|
|
|
@ -63,8 +63,7 @@ export const keydown =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortDeduplication = (array) => {
|
const sortDeduplication = (array, memorySpace = 5) => {
|
||||||
const memorySpace = 5 // 一个name的记忆量
|
|
||||||
const length = array.length
|
const length = array.length
|
||||||
let newArray = []
|
let newArray = []
|
||||||
let fillterObj = {}
|
let fillterObj = {}
|
||||||
|
@ -106,7 +105,7 @@ const isJSONobject = (string, type) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const setLocalStorageage = (name, value) => {
|
const setLocalStorageage = (name, value, memorySpace = 5) => {
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
const oldValue = localStorage.getItem(name)
|
const oldValue = localStorage.getItem(name)
|
||||||
const isArray = isJSONobject(oldValue, Array)
|
const isArray = isJSONobject(oldValue, Array)
|
||||||
|
@ -116,7 +115,7 @@ const setLocalStorageage = (name, value) => {
|
||||||
let oldArray = JSON.parse(localStorage.getItem(name))
|
let oldArray = JSON.parse(localStorage.getItem(name))
|
||||||
|
|
||||||
oldArray.unshift(value)
|
oldArray.unshift(value)
|
||||||
oldArray = sortDeduplication(oldArray)
|
oldArray = sortDeduplication(oldArray, memorySpace)
|
||||||
newValue = JSON.stringify(oldArray)
|
newValue = JSON.stringify(oldArray)
|
||||||
} else if (oldValue === null || oldValue === value) {
|
} else if (oldValue === null || oldValue === value) {
|
||||||
newValue = value
|
newValue = value
|
||||||
|
@ -130,7 +129,7 @@ const setLocalStorageage = (name, value) => {
|
||||||
|
|
||||||
export const addMemory = (props) => (value) => {
|
export const addMemory = (props) => (value) => {
|
||||||
if (props.name && value) {
|
if (props.name && value) {
|
||||||
setLocalStorageage(props.name, value)
|
setLocalStorageage(props.name, value, props.memorySpace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
.component-css-vars-tall-storage();
|
.component-css-vars-tall-storage();
|
||||||
|
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-top: 2px;
|
|
||||||
|
|
||||||
.@{storage-list-style-prefix-cls} {
|
.@{storage-list-style-prefix-cls} {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -36,6 +35,8 @@
|
||||||
.@{storage-list-prefix-cls} {
|
.@{storage-list-prefix-cls} {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
overflow-y: auto;
|
||||||
|
max-height: calc(var(--ti-tall-storage-item-height) * 5);
|
||||||
|
|
||||||
.@{storage-item-prefix-cls} {
|
.@{storage-item-prefix-cls} {
|
||||||
height: var(--ti-tall-storage-item-height);
|
height: var(--ti-tall-storage-item-height);
|
||||||
|
|
|
@ -60,6 +60,10 @@ export const inputProps = {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'text'
|
default: 'text'
|
||||||
},
|
},
|
||||||
|
memorySpace: {
|
||||||
|
type: Number,
|
||||||
|
default: 5
|
||||||
|
},
|
||||||
vertical: {
|
vertical: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
|
|
@ -247,6 +247,7 @@ export default defineComponent({
|
||||||
'prefixIcon',
|
'prefixIcon',
|
||||||
'autocomplete',
|
'autocomplete',
|
||||||
'showPassword',
|
'showPassword',
|
||||||
|
'memorySpace',
|
||||||
'validateEvent',
|
'validateEvent',
|
||||||
'showWordLimit',
|
'showWordLimit',
|
||||||
'displayOnly',
|
'displayOnly',
|
||||||
|
|
Loading…
Reference in New Issue