code refactor

This commit is contained in:
MaysWind
2023-08-13 14:58:11 +08:00
parent fa3e941069
commit f6a2246aab
5 changed files with 22 additions and 44 deletions
+2 -11
View File
@@ -39,6 +39,7 @@
</template>
<script>
import { arrayContainsFieldvalue } from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
import {
@@ -96,17 +97,7 @@ export default {
},
methods: {
hasSelectedIcon(row) {
if (!this.modelValue || !row || !row.length) {
return false;
}
for (let i = 0; i < row.length; i++) {
if (row[i].id === this.modelValue) {
return true;
}
}
return false;
return arrayContainsFieldvalue(row, 'id', this.modelValue);
},
onMenuStateChanged(state) {
const self = this;
+2 -11
View File
@@ -37,6 +37,7 @@
</template>
<script>
import { arrayContainsFieldvalue } from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
import {
@@ -104,17 +105,7 @@ export default {
},
methods: {
hasSelectedIcon(row) {
if (!this.modelValue || !row || !row.length) {
return false;
}
for (let i = 0; i < row.length; i++) {
if (row[i].id === this.modelValue) {
return true;
}
}
return false;
return arrayContainsFieldvalue(row, 'id', this.modelValue);
},
onMenuStateChanged(state) {
const self = this;
+2 -11
View File
@@ -29,6 +29,7 @@
</template>
<script>
import { arrayContainsFieldvalue } from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
export default {
@@ -81,17 +82,7 @@ export default {
this.$emit('update:show', false);
},
hasSelectedIcon(row) {
if (!this.currentValue || !row || !row.length) {
return false;
}
for (let i = 0; i < row.length; i++) {
if (row[i].id === this.currentValue) {
return true;
}
}
return false;
return arrayContainsFieldvalue(row, 'id', this.currentValue);
}
}
}
+2 -11
View File
@@ -29,6 +29,7 @@
</template>
<script>
import { arrayContainsFieldvalue } from '@/lib/common.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
export default {
@@ -101,17 +102,7 @@ export default {
this.$emit('update:show', false);
},
hasSelectedIcon(row) {
if (!this.currentValue || !row || !row.length) {
return false;
}
for (let i = 0; i < row.length; i++) {
if (row[i].id === this.currentValue) {
return true;
}
}
return false;
return arrayContainsFieldvalue(row, 'id', this.currentValue);
}
}
}
+14
View File
@@ -331,6 +331,20 @@ export function copyArrayTo(fromArray, toArray) {
return toArray;
}
export function arrayContainsFieldvalue(array, fieldName, value) {
if (!value || !array || !array.length) {
return false;
}
for (let i = 0; i < array.length; i++) {
if (array[i][fieldName] === value) {
return true;
}
}
return false;
}
export function categoriedArrayToPlainArray(object) {
const ret = [];