Skip to content

Commit

Permalink
feat: add "reset owned" option for depot import
Browse files Browse the repository at this point in the history
close #256
  • Loading branch information
Tsuk1ko committed Oct 17, 2023
1 parent 94fcda3 commit 8e66db1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/data/changelog.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[
{
"time": "2023-10-17",
"changes": ["【精英材料计算】增加模组图标", "【仓库材料导入】增加“重置已有”选项"]
},
{
"time": "2023-09-14",
"changes": ["【精英材料计算】预设搜索支持显示已添加的干员"]
Expand Down
16 changes: 15 additions & 1 deletion src/views/Depot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
>{{ $t('common.import') }}</button
>
</div>
<div class="mdui-col-xs-12 mdui-m-t-2">
<mdui-checkbox v-model="resetOwned">{{
$t('cultivate.panel.button.resetOwned')
}}</mdui-checkbox>
</div>
</div>
</template>
<!-- 选图提示 -->
Expand Down Expand Up @@ -176,6 +181,7 @@ export default defineComponent({
drError: '',
drDebug: [],
debug: false,
resetOwned: false,
}),
computed: {
...mapState(useDataStore, ['materialTable']),
Expand Down Expand Up @@ -289,8 +295,16 @@ export default defineComponent({
},
importItems() {
if (this.$root.importItemsListening) {
this.$root.$emit('import-items', this.itemsWillBeImported);
if (this.resetOwned) {
this.resetOwned = false;
this.$root.$emit('import-items', 'reset');
}
this.$root.$emit('import-items', 'import', this.itemsWillBeImported);
} else {
if (this.resetOwned) {
this.resetOwned = false;
nls.setItem('reset', true);
}
const items = {
...(nls.getItem('imports') || {}),
...this.itemsWillBeImported,
Expand Down
28 changes: 21 additions & 7 deletions src/views/Material/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import IreneCalculatorDialog from '@/components/material/IreneCalculatorDialog.v
import LazyDialog from '@/components/LazyDialog.vue';

import Ajax from '@/utils/ajax';
import safelyParseJSON from '@/utils/safelyParseJSON';
import * as clipboard from '@/utils/clipboard';
import pickClone from '@/utils/pickClone';
import { MATERIAL_TAG_BTN_COLOR } from '@/utils/constant';
import MultiAccount from '@/utils/MultiAccount';
import NamespacedLocalStorage from '@/utils/NamespacedLocalStorage';
import { useDataStore, MaterialTypeEnum, PURCHASE_CERTIFICATE_ID } from '@/store/data';
import { usePenguinDataStore } from '@/store/penguinData';
import { useMaterialValueStore } from '@/store/materialValue';
Expand Down Expand Up @@ -1621,6 +1621,16 @@ export default defineComponent({
const remainder = morale % 24;
return people > 0 ? `${people} * 24` + (remainder ? ` + ${remainder}` : '') : remainder;
},
handleImportItemsEvent(type, data) {
switch (type) {
case 'import':
this.importItems(data);
break;
case 'reset':
this.reset('have', false, false);
break;
}
},
importItems(items) {
_.each(items, (num, name) => {
const input = this.inputs[name];
Expand Down Expand Up @@ -1757,16 +1767,20 @@ export default defineComponent({
trailing: true,
});

this.$root.$on('import-items', this.importItems);
this.$root.$on('import-items', this.handleImportItemsEvent);
this.$root.importItemsListening = true;

this.initFromStorage();

const itemsImportStorageKey = 'depot.imports';
if (itemsImportStorageKey in (window.localStorage || {})) {
const depotLs = new NamespacedLocalStorage('depot');
if (depotLs.has('imports')) {
if (depotLs.getItem('reset')) {
this.reset('have', false, false);
}
this.ignoreNextInputsChange = false;
const items = safelyParseJSON(window.localStorage.getItem(itemsImportStorageKey));
window.localStorage.removeItem(itemsImportStorageKey);
const items = depotLs.getItem('imports');
depotLs.removeItem('reset');
depotLs.removeItem('imports');
this.importItems(items);
}
},
Expand All @@ -1784,7 +1798,7 @@ export default defineComponent({
},
beforeDestroy() {
this.$root.importItemsListening = false;
this.$root.$off('import-items');
this.$root.$off('import-items', this.handleImportItemsEvent);
multiAccount.emitter.off('change', this.initFromStorage);
},
});

0 comments on commit 8e66db1

Please sign in to comment.