changes
This commit is contained in:
@@ -1,55 +1,61 @@
|
||||
<template>
|
||||
<!-- v-if="currentsetting ? currentsetting.user === login.id : false" -->
|
||||
<div
|
||||
class="mb-4"
|
||||
v-if="currentsetting ? currentsetting.user === login.id : false"
|
||||
v-if="currentsetting"
|
||||
>
|
||||
<p class="fs-16 has-text-findata">
|
||||
<p>
|
||||
Đang mở: <b>{{ $stripHtml(currentsetting.name, 40) }}</b>
|
||||
</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label fs-14">Chọn chế độ lưu <span class="has-text-danger"> * </span></label>
|
||||
<label class="label">Chọn chế độ lưu <span class="has-text-danger"> * </span></label>
|
||||
<div class="control is-expanded fs-14">
|
||||
<a
|
||||
class="mr-5"
|
||||
<button
|
||||
class="button is-white has-text-inherit"
|
||||
v-if="isOverwrite()"
|
||||
@click="changeType('overwrite')"
|
||||
>
|
||||
<span class="icon-text">
|
||||
<SvgIcon
|
||||
v-bind="{
|
||||
name: radioSave === 'overwrite' ? 'radio-checked.svg' : 'radio-unchecked.svg',
|
||||
type: 'gray',
|
||||
size: 22,
|
||||
}"
|
||||
></SvgIcon>
|
||||
Ghi đè
|
||||
<span class="icon">
|
||||
<Icon
|
||||
:name="
|
||||
radioSave === 'overwrite'
|
||||
? 'material-symbols:radio-button-checked-outline'
|
||||
: 'material-symbols:radio-button-unchecked'
|
||||
"
|
||||
:size="22"
|
||||
/>
|
||||
</span>
|
||||
</a>
|
||||
<a @click="changeType('new')">
|
||||
<span class="icon-text">
|
||||
<SvgIcon
|
||||
v-bind="{
|
||||
name: radioSave === 'new' ? 'radio-checked.svg' : 'radio-unchecked.svg',
|
||||
type: 'gray',
|
||||
size: 22,
|
||||
}"
|
||||
></SvgIcon>
|
||||
Tạo mới
|
||||
<span>Ghi đè</span>
|
||||
</button>
|
||||
<button
|
||||
class="button is-white"
|
||||
@click="changeType('new')"
|
||||
>
|
||||
<span class="icon">
|
||||
<Icon
|
||||
:name="
|
||||
radioSave === 'new'
|
||||
? 'material-symbols:radio-button-checked-outline'
|
||||
: 'material-symbols:radio-button-unchecked'
|
||||
"
|
||||
:size="22"
|
||||
/>
|
||||
</span>
|
||||
</a>
|
||||
<span>Tạo mới</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<template v-if="radioSave === 'new'">
|
||||
<div class="field mt-4 px-0 mx-0">
|
||||
<label class="label fs-14">Tên thiết lập <span class="has-text-danger"> * </span></label>
|
||||
<div class="field">
|
||||
<label class="label">Tên thiết lập <span class="has-text-danger"> * </span></label>
|
||||
<div class="control">
|
||||
<!-- ref="name" -->
|
||||
<input
|
||||
class="input"
|
||||
type="text"
|
||||
placeholder=""
|
||||
v-model="name"
|
||||
ref="name"
|
||||
v-on:keyup.enter="saveSetting"
|
||||
/>
|
||||
</div>
|
||||
@@ -60,12 +66,12 @@
|
||||
{{ errors.find((v) => v.name === "name").msg }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="field mt-4 px-0 mx-0">
|
||||
<label class="label fs-14"> Mô tả </label>
|
||||
<div class="field">
|
||||
<label class="label"> Mô tả </label>
|
||||
<p class="control is-expanded">
|
||||
<textarea
|
||||
class="textarea"
|
||||
rows="4"
|
||||
rows="3"
|
||||
v-model="note"
|
||||
></textarea>
|
||||
</p>
|
||||
@@ -93,11 +99,12 @@
|
||||
{{ status ? "Lưu thiết lập thành công." : "Lỗi. Lưu thiết lập thất bại." }}
|
||||
</label>
|
||||
<p class="control is-expanded">
|
||||
<a
|
||||
class="button is-primary has-text-white"
|
||||
<button
|
||||
:class="['button is-primary', isLoading && 'is-loading']"
|
||||
@click="saveSetting()"
|
||||
>Lưu lại</a
|
||||
>
|
||||
Lưu lại
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -106,28 +113,30 @@ import { ref } from "vue";
|
||||
import { useStore } from "@/stores/index";
|
||||
const emit = defineEmits([]);
|
||||
const store = useStore();
|
||||
var props = defineProps({
|
||||
const props = defineProps({
|
||||
pagename: String,
|
||||
classify: String,
|
||||
option: String,
|
||||
data: Object,
|
||||
focus: Boolean,
|
||||
});
|
||||
const { $empty, $copy, $filter, $stripHtml, $updateapi, $insertapi, $findIndex, $snackbar } = useNuxtApp();
|
||||
var pagename = props.pagename;
|
||||
var radioOption = ref();
|
||||
const { $empty, $copy, $stripHtml, $updateapi, $insertapi, $findIndex, $snackbar } = useNuxtApp();
|
||||
const radioOption = ref();
|
||||
var login = { id: 1 };
|
||||
var errors = [];
|
||||
var radioType = undefined;
|
||||
var radioDefault = 0;
|
||||
var radioSave = ref("new");
|
||||
var note = undefined;
|
||||
var status = undefined;
|
||||
var name = undefined;
|
||||
const errors = ref([]);
|
||||
const radioType = ref();
|
||||
const radioDefault = 0;
|
||||
const radioSave = ref("overwrite");
|
||||
const name = ref();
|
||||
const note = ref();
|
||||
const status = undefined;
|
||||
var currentsetting = undefined;
|
||||
var pagename = props.pagename;
|
||||
var pagedata = store[props.pagename];
|
||||
const isLoading = ref(false);
|
||||
|
||||
async function saveSetting() {
|
||||
errors = [];
|
||||
errors.value = [];
|
||||
let detail = pagename ? { fields: pagedata.fields } : {};
|
||||
if (pagename) {
|
||||
let element = pagedata.tablesetting || {};
|
||||
@@ -139,19 +148,21 @@ async function saveSetting() {
|
||||
if (props.option) detail.option = props.option;
|
||||
if (props.data) detail.data = props.data;
|
||||
let data = {
|
||||
user: login.id,
|
||||
name: name,
|
||||
detail: detail,
|
||||
note: note,
|
||||
type: radioType.id,
|
||||
// user: login.id,
|
||||
user: undefined,
|
||||
name: name.value,
|
||||
detail,
|
||||
note,
|
||||
type: radioType.value.id,
|
||||
classify: props.classify ? props.classify : store.settingclass.find((v) => v.code === "data-field").id,
|
||||
default: radioDefault,
|
||||
update_time: new Date(),
|
||||
};
|
||||
let result;
|
||||
isLoading.value = true;
|
||||
if (radioSave.value === "new") {
|
||||
if ($empty(name)) {
|
||||
return errors.push({
|
||||
if ($empty(name.value)) {
|
||||
return errors.value.push({
|
||||
name: "name",
|
||||
msg: "Tên thiết lập không được bỏ trống",
|
||||
});
|
||||
@@ -163,6 +174,7 @@ async function saveSetting() {
|
||||
copy.update_time = new Date();
|
||||
result = await $updateapi("usersetting", copy);
|
||||
}
|
||||
isLoading.value = false;
|
||||
if (radioSave.value === "new") {
|
||||
emit("modalevent", { name: "opensetting", data: result });
|
||||
} else {
|
||||
@@ -187,11 +199,12 @@ function changeOption(v) {
|
||||
radioOption.value = v.code;
|
||||
}
|
||||
function initData() {
|
||||
radioType = store.settingtype.find((v) => v.code === "private");
|
||||
radioType.value = store.settingtype.find((v) => v.code === "private");
|
||||
if (props.pagename) currentsetting = $copy(pagedata.setting ? pagedata.setting : undefined);
|
||||
if (!currentsetting) radioSave.value = "new";
|
||||
// disable temp: for now, radioSave is always 'overwrite'
|
||||
/* if (!currentsetting) radioSave.value = "new";
|
||||
else if (currentsetting.user !== login.id) radioSave.value = "new";
|
||||
else radioSave.value = "overwrite";
|
||||
else radioSave.value = "overwrite"; */
|
||||
}
|
||||
initData();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user