mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
code refactor
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -96,17 +97,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
hasSelectedIcon(row) {
|
hasSelectedIcon(row) {
|
||||||
if (!this.modelValue || !row || !row.length) {
|
return arrayContainsFieldvalue(row, 'id', this.modelValue);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < row.length; i++) {
|
|
||||||
if (row[i].id === this.modelValue) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
onMenuStateChanged(state) {
|
onMenuStateChanged(state) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -104,17 +105,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
hasSelectedIcon(row) {
|
hasSelectedIcon(row) {
|
||||||
if (!this.modelValue || !row || !row.length) {
|
return arrayContainsFieldvalue(row, 'id', this.modelValue);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < row.length; i++) {
|
|
||||||
if (row[i].id === this.modelValue) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
onMenuStateChanged(state) {
|
onMenuStateChanged(state) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -81,17 +82,7 @@ export default {
|
|||||||
this.$emit('update:show', false);
|
this.$emit('update:show', false);
|
||||||
},
|
},
|
||||||
hasSelectedIcon(row) {
|
hasSelectedIcon(row) {
|
||||||
if (!this.currentValue || !row || !row.length) {
|
return arrayContainsFieldvalue(row, 'id', this.currentValue);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < row.length; i++) {
|
|
||||||
if (row[i].id === this.currentValue) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -101,17 +102,7 @@ export default {
|
|||||||
this.$emit('update:show', false);
|
this.$emit('update:show', false);
|
||||||
},
|
},
|
||||||
hasSelectedIcon(row) {
|
hasSelectedIcon(row) {
|
||||||
if (!this.currentValue || !row || !row.length) {
|
return arrayContainsFieldvalue(row, 'id', this.currentValue);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < row.length; i++) {
|
|
||||||
if (row[i].id === this.currentValue) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -331,6 +331,20 @@ export function copyArrayTo(fromArray, toArray) {
|
|||||||
return 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) {
|
export function categoriedArrayToPlainArray(object) {
|
||||||
const ret = [];
|
const ret = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user