code refactor
This commit is contained in:
@@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||||
|
import { getColorsInRows } from '@/lib/color.js';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -71,20 +72,7 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
allColorRows() {
|
allColorRows() {
|
||||||
const ret = [];
|
return getColorsInRows(this.allColorInfos, this.itemPerRow);
|
||||||
let rowCount = -1;
|
|
||||||
|
|
||||||
for (let i = 0; i < this.allColorInfos.length; i++) {
|
|
||||||
if (i % this.itemPerRow === 0) {
|
|
||||||
ret[++rowCount] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
ret[rowCount].push({
|
|
||||||
color: this.allColorInfos[i]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
},
|
},
|
||||||
color: {
|
color: {
|
||||||
get: function () {
|
get: function () {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||||
|
import { getIconsInRows } from '@/lib/icon.js';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -69,30 +70,7 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
allIconRows() {
|
allIconRows() {
|
||||||
const ret = [];
|
return getIconsInRows(this.allIconInfos, this.itemPerRow);
|
||||||
let rowCount = 0;
|
|
||||||
|
|
||||||
for (let iconInfoId in this.allIconInfos) {
|
|
||||||
if (!Object.prototype.hasOwnProperty.call(this.allIconInfos, iconInfoId)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const iconInfo = this.allIconInfos[iconInfoId];
|
|
||||||
|
|
||||||
if (!ret[rowCount]) {
|
|
||||||
ret[rowCount] = [];
|
|
||||||
} else if (ret[rowCount] && ret[rowCount].length >= this.itemPerRow) {
|
|
||||||
rowCount++;
|
|
||||||
ret[rowCount] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
ret[rowCount].push({
|
|
||||||
id: iconInfoId,
|
|
||||||
icon: iconInfo.icon
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
},
|
},
|
||||||
icon: {
|
icon: {
|
||||||
get: function () {
|
get: function () {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||||
|
import { getColorsInRows } from '@/lib/color.js';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -53,20 +54,7 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
allColorRows() {
|
allColorRows() {
|
||||||
const ret = [];
|
return getColorsInRows(this.allColorInfos, this.itemPerRow);
|
||||||
let rowCount = -1;
|
|
||||||
|
|
||||||
for (let i = 0; i < this.allColorInfos.length; i++) {
|
|
||||||
if (i % this.itemPerRow === 0) {
|
|
||||||
ret[++rowCount] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
ret[rowCount].push({
|
|
||||||
color: this.allColorInfos[i]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||||
|
import { getIconsInRows } from '@/lib/icon.js';
|
||||||
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -54,30 +55,7 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
allIconRows() {
|
allIconRows() {
|
||||||
const ret = [];
|
return getIconsInRows(this.allIconInfos, this.itemPerRow);
|
||||||
let rowCount = 0;
|
|
||||||
|
|
||||||
for (let iconInfoId in this.allIconInfos) {
|
|
||||||
if (!Object.prototype.hasOwnProperty.call(this.allIconInfos, iconInfoId)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const iconInfo = this.allIconInfos[iconInfoId];
|
|
||||||
|
|
||||||
if (!ret[rowCount]) {
|
|
||||||
ret[rowCount] = [];
|
|
||||||
} else if (ret[rowCount] && ret[rowCount].length >= this.itemPerRow) {
|
|
||||||
rowCount++;
|
|
||||||
ret[rowCount] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
ret[rowCount].push({
|
|
||||||
id: iconInfoId,
|
|
||||||
icon: iconInfo.icon
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
},
|
},
|
||||||
heightClass() {
|
heightClass() {
|
||||||
if (this.allIconRows.length > 10) {
|
if (this.allIconRows.length > 10) {
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
export function getColorsInRows(allColorInfos, itemPerRow) {
|
||||||
|
const ret = [];
|
||||||
|
let rowCount = -1;
|
||||||
|
|
||||||
|
for (let i = 0; i < allColorInfos.length; i++) {
|
||||||
|
if (i % itemPerRow === 0) {
|
||||||
|
ret[++rowCount] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
ret[rowCount].push({
|
||||||
|
color: allColorInfos[i]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
export function getIconsInRows(allIconInfos, itemPerRow) {
|
||||||
|
const ret = [];
|
||||||
|
let rowCount = 0;
|
||||||
|
|
||||||
|
for (let iconInfoId in allIconInfos) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(allIconInfos, iconInfoId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const iconInfo = allIconInfos[iconInfoId];
|
||||||
|
|
||||||
|
if (!ret[rowCount]) {
|
||||||
|
ret[rowCount] = [];
|
||||||
|
} else if (ret[rowCount] && ret[rowCount].length >= itemPerRow) {
|
||||||
|
rowCount++;
|
||||||
|
ret[rowCount] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
ret[rowCount].push({
|
||||||
|
id: iconInfoId,
|
||||||
|
icon: iconInfo.icon
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user