2024-07-30 18:45:05 -04:00
|
|
|
<script>
|
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
import {fetchPost} from "@/utilities/fetch.js";
|
|
|
|
|
import {DashboardConfigurationStore} from "@/stores/DashboardConfigurationStore.js";
|
2024-08-06 19:15:00 -04:00
|
|
|
import VueDatePicker from "@vuepic/vue-datepicker";
|
2024-09-12 15:21:42 +08:00
|
|
|
import LocaleText from "@/components/text/localeText.vue";
|
2024-07-30 18:45:05 -04:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "newDashboardAPIKey",
|
2024-09-12 15:21:42 +08:00
|
|
|
components: {LocaleText, VueDatePicker},
|
2024-07-30 18:45:05 -04:00
|
|
|
data(){
|
|
|
|
|
return{
|
|
|
|
|
newKeyData:{
|
2024-08-06 19:15:00 -04:00
|
|
|
ExpiredAt: dayjs().add(7, 'd').format("YYYY-MM-DD HH:mm:ss"),
|
2025-04-19 02:54:47 +08:00
|
|
|
NeverExpire: false
|
2024-07-30 18:45:05 -04:00
|
|
|
},
|
|
|
|
|
submitting: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
setup(){
|
|
|
|
|
const store = DashboardConfigurationStore();
|
|
|
|
|
return {store};
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
console.log(this.newKeyData.ExpiredAt)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
submitNewAPIKey(){
|
|
|
|
|
this.submitting = true;
|
|
|
|
|
fetchPost('/api/newDashboardAPIKey', this.newKeyData, (res) => {
|
|
|
|
|
if (res.status){
|
|
|
|
|
this.$emit('created', res.data);
|
2024-09-22 21:50:30 +08:00
|
|
|
this.store.newMessage("Server", "API Key created", "success");
|
2024-07-30 18:45:05 -04:00
|
|
|
this.$emit('close')
|
|
|
|
|
}else{
|
|
|
|
|
this.store.newMessage("Server", res.message, "danger")
|
|
|
|
|
}
|
|
|
|
|
this.submitting = false;
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
fixDate(date){
|
|
|
|
|
console.log(dayjs(date).format("YYYY-MM-DDTHH:mm:ss"))
|
|
|
|
|
return dayjs(date).format("YYYY-MM-DDTHH:mm:ss")
|
2024-08-06 19:15:00 -04:00
|
|
|
},
|
|
|
|
|
parseTime(modelData){
|
|
|
|
|
if(modelData){
|
|
|
|
|
this.newKeyData.ExpiredAt = dayjs(modelData).format("YYYY-MM-DD HH:mm:ss");
|
|
|
|
|
}else{
|
|
|
|
|
this.newKeyData.ExpiredAt = undefined
|
|
|
|
|
}
|
2024-07-30 18:45:05 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="position-absolute w-100 h-100 top-0 start-0 rounded-bottom-3 p-3 d-flex"
|
2025-09-01 17:16:03 +08:00
|
|
|
style="background-color: #00000060; backdrop-filter: blur(3px); z-index: 9999">
|
2024-07-30 18:45:05 -04:00
|
|
|
<div class="card m-auto rounded-3 mt-5">
|
|
|
|
|
<div class="card-header bg-transparent d-flex align-items-center gap-2 border-0 p-4 pb-0">
|
2024-09-12 15:21:42 +08:00
|
|
|
<h6 class="mb-0">
|
|
|
|
|
<LocaleText t="Create API Key"></LocaleText>
|
|
|
|
|
</h6>
|
2024-07-30 18:45:05 -04:00
|
|
|
<button type="button" class="btn-close ms-auto" @click="this.$emit('close')"></button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-body d-flex gap-2 p-4 flex-column">
|
2024-09-12 15:21:42 +08:00
|
|
|
<small class="text-muted">
|
|
|
|
|
<LocaleText t="When should this API Key expire?"></LocaleText>
|
|
|
|
|
</small>
|
2024-07-30 18:45:05 -04:00
|
|
|
<div class="d-flex align-items-center gap-2">
|
2024-08-06 19:15:00 -04:00
|
|
|
<VueDatePicker
|
2025-09-01 17:16:03 +08:00
|
|
|
style="z-index: 9999"
|
2024-08-06 19:15:00 -04:00
|
|
|
:is24="true"
|
|
|
|
|
:min-date="new Date()"
|
|
|
|
|
:model-value="this.newKeyData.ExpiredAt"
|
|
|
|
|
@update:model-value="this.parseTime" time-picker-inline
|
|
|
|
|
format="yyyy-MM-dd HH:mm:ss"
|
|
|
|
|
preview-format="yyyy-MM-dd HH:mm:ss"
|
|
|
|
|
:clearable="false"
|
2025-04-19 02:54:47 +08:00
|
|
|
:disabled="this.newKeyData.NeverExpire || this.submitting"
|
2024-08-06 19:15:00 -04:00
|
|
|
:dark="this.store.Configuration.Server.dashboard_theme === 'dark'"
|
|
|
|
|
/>
|
2024-07-30 18:45:05 -04:00
|
|
|
</div>
|
|
|
|
|
<div class="form-check">
|
|
|
|
|
<input class="form-check-input" type="checkbox"
|
2025-04-19 02:54:47 +08:00
|
|
|
v-model="this.newKeyData.NeverExpire" id="neverExpire" :disabled="this.submitting">
|
2024-07-30 18:45:05 -04:00
|
|
|
<label class="form-check-label" for="neverExpire">
|
2024-09-12 15:21:42 +08:00
|
|
|
<LocaleText t="Never Expire"></LocaleText> (<i class="bi bi-emoji-grimace-fill me-2"></i>
|
|
|
|
|
<LocaleText t="Don't think that's a good idea"></LocaleText>)
|
2024-07-30 18:45:05 -04:00
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
<button class="ms-auto btn bg-success-subtle text-success-emphasis border-1 border-success-subtle rounded-3 shadow-sm"
|
|
|
|
|
:class="{disabled: this.submitting}"
|
|
|
|
|
@click="this.submitNewAPIKey()"
|
|
|
|
|
>
|
|
|
|
|
<i class="bi bi-check-lg me-2" v-if="!this.submitting"></i>
|
2024-09-12 15:21:42 +08:00
|
|
|
<LocaleText t="Creating..." v-if="this.submitting"></LocaleText>
|
|
|
|
|
<LocaleText t="Create" v-else></LocaleText>
|
2024-07-30 18:45:05 -04:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
|
|
</style>
|