Commit 980628c0 authored by xiaoye's avatar xiaoye

Update api.vue

parent 0868d937
...@@ -45,9 +45,9 @@ ...@@ -45,9 +45,9 @@
</template> </template>
</uni-list-item> </uni-list-item>
<uni-forms v-show = 'api.changing == v'> <uni-forms v-show = 'api.changing == v'>
<uni-datetime-picker type = 'datetime' v-model = 'api.changeInfo.date'/> <uni-datetime-picker type = 'datetime' v-model = 'api.changeInfo[v].date'/>
<uni-easyinput type = 'text' placeholder = '名称' v-model = 'api.changeInfo.name'/> <uni-easyinput type = 'text' placeholder = '名称' v-model = 'api.changeInfo[v].name'/>
<uni-easyinput type = 'text' placeholder = '描述' v-model = 'api.changeInfo.description'/> <uni-easyinput type = 'text' placeholder = '描述' v-model = 'api.changeInfo[v].description'/>
<view <view
class = 'button' class = 'button'
@click = 'api.update(i.id, v)' @click = 'api.update(i.id, v)'
...@@ -90,8 +90,6 @@ ...@@ -90,8 +90,6 @@
</template> </template>
<script setup lang = 'ts'> <script setup lang = 'ts'>
import { ref, reactive, onMounted, onUnmounted, onBeforeMount, watch} from 'vue'; import { ref, reactive, onMounted, onUnmounted, onBeforeMount, watch} from 'vue';
import emitter from '../../script/emitter.ts';
import Const from '../../script/const.ts'
import Mycard from '../../script/mycard.ts'; import Mycard from '../../script/mycard.ts';
import ApiKey from '../../script/apikey.ts'; import ApiKey from '../../script/apikey.ts';
import UniApp from '../../script/uniapp.ts'; import UniApp from '../../script/uniapp.ts';
...@@ -133,30 +131,13 @@ ...@@ -133,30 +131,13 @@
UniApp.copy(i.key); UniApp.copy(i.key);
}, },
change : (v : number) : void => { change : (v : number) : void => {
if (api.changing == v) { api.changing = api.changing == v ? -1 : v;
api.changing = -1;
api.changeInfo = {
date : '',
name : '',
description : '',
expireAt : undefined as undefined | Date
};
} else {
const i = api.list[v];
api.changeInfo = {
date : i.expireAt,
name : i.name,
description : i.description,
expireAt : new Date(i.expireAt)
};
api.changing = v;
}
}, },
update : async (id : number, v : number) : Promise<void> => { update : async (id : number, v : number) : Promise<void> => {
if (await Tabulator.ApiKey.Update(Mycard.token, id, { if (await Tabulator.ApiKey.Update(Mycard.token, id, {
name : api.changeInfo.name, name : api.changeInfo[v].name,
description : api.changeInfo.description, description : api.changeInfo[v].description,
expireAt : api.changeInfo.expireAt expireAt : api.changeInfo[v].date?.length ?? 0 > 0 ? new Date(api.changeInfo[v].date) : undefined
} as ApiKeyCreateObject)) } as ApiKeyCreateObject))
api.search(); api.search();
}, },
...@@ -167,44 +148,28 @@ ...@@ -167,44 +148,28 @@
} as ApiKeyCreateObject, } as ApiKeyCreateObject,
date : '', date : '',
changing : -1, changing : -1,
changeInfo : { changeInfo : [] as Array<{
date : '', date : string;
name : '', name : string;
description : '', description : string;
expireAt : undefined as undefined | Date }>
}
}); });
watch(() => { return api.date; }, () => { watch(() => { return api.date; }, () => {
const toDate = () => { api.info.expireAt = api.date.length > 0 ? new Date(api.date) : undefined;
api.info.expireAt = new Date(api.date);
};
const toUndefined = () => {
api.info.expireAt = undefined;
};
api.date.length > 0 ? toDate() : toUndefined();
}); });
watch(() => { return api.list; }, () => { watch(() => { return api.list; }, () => {
api.changing = -1; api.changing = -1;
api.changeInfo = { api.list.forEach(i => {
date : '', api.changeInfo.push({
name : '', date : i.expireAt,
description : '', name : i.name,
expireAt : undefined as undefined | Date description : i.description,
}; });
});
}, { deep : true }); }, { deep : true });
watch(() => { return api.changeInfo.date; }, () => {
const toDate = () => {
api.changeInfo.expireAt = new Date(api.changeInfo.date);
};
const toUndefined = () => {
api.changeInfo.expireAt = undefined;
};
api.changeInfo.date?.length ?? 0 > 0 ? toDate() : toUndefined();
});
onBeforeMount(() : void => { onBeforeMount(() : void => {
api.search(); api.search();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment