changes
This commit is contained in:
@@ -223,7 +223,7 @@ const {
|
||||
$resetNull,
|
||||
$findapi,
|
||||
$insertapi,
|
||||
$updateapi,
|
||||
$patchapi,
|
||||
$remove,
|
||||
$deleteapi,
|
||||
$empty,
|
||||
@@ -315,7 +315,7 @@ async function update() {
|
||||
data.link = arr1.length === 0 ? null : arr1;
|
||||
let api = $findapi("useraction");
|
||||
record = data.id
|
||||
? await $updateapi("useraction", { data, values: api.params.values })
|
||||
? await $patchapi("useraction", { data, values: api.params.values })
|
||||
: await $insertapi("useraction", { data, values: api.params.values });
|
||||
getValue();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</template>
|
||||
<script setup>
|
||||
const emit = defineEmits(["close"]);
|
||||
const { $store, $getdata, $updateapi, $updatepage } = useNuxtApp();
|
||||
const { $store, $getdata, $patchapi, $updatepage } = useNuxtApp();
|
||||
const props = defineProps({
|
||||
row: Object,
|
||||
pagename: String,
|
||||
@@ -31,7 +31,7 @@ let record = await $getdata("application", {
|
||||
first: true,
|
||||
});
|
||||
async function save() {
|
||||
await $updateapi("application", record);
|
||||
await $patchapi("application", record);
|
||||
record = await $getdata("application", {
|
||||
filter: { id: props.row.id },
|
||||
first: true,
|
||||
|
||||
@@ -119,7 +119,7 @@ export default {
|
||||
data = this.$copy(this.current);
|
||||
data.detail = this.detail;
|
||||
}
|
||||
let rs = data.id ? await this.$updateapi(this.api, data) : await this.$insertapi(this.api, { data });
|
||||
let rs = data.id ? await this.$patchapi(this.api, data) : await this.$insertapi(this.api, { data });
|
||||
if (!rs) return;
|
||||
this.detail = undefined;
|
||||
if (this.current) {
|
||||
|
||||
@@ -205,7 +205,7 @@ var props = defineProps({
|
||||
row: Object,
|
||||
});
|
||||
const store = useStore();
|
||||
const { $find, $getdata, $updateapi, $insertapi, $findapi, $getapi, $empty, $errPhone, $resetNull, $snackbar } =
|
||||
const { $find, $getdata, $patchapi, $insertapi, $findapi, $getapi, $empty, $errPhone, $resetNull, $snackbar } =
|
||||
useNuxtApp();
|
||||
const emit = defineEmits(["update", "dataevent"]);
|
||||
var viewport = store.viewport;
|
||||
@@ -271,7 +271,7 @@ async function update() {
|
||||
record.value.updater = store.login.id;
|
||||
record.update_time = new Date();
|
||||
let rs = record.value.id
|
||||
? await $updateapi("company", record.value)
|
||||
? await $patchapi("company", record.value)
|
||||
: await $insertapi("company", { data: record.value });
|
||||
if (rs === "error") return;
|
||||
if (!record.value.id) $snackbar(`Khách hàng đã được khởi tạo với mã <b>${rs.code}</b>`, "Success");
|
||||
|
||||
@@ -120,7 +120,7 @@ const props = defineProps({
|
||||
data: Object,
|
||||
focus: Boolean,
|
||||
});
|
||||
const { $empty, $copy, $copyToClipboard, $stripHtml, $updateapi, $insertapi, $findIndex, $snackbar } = useNuxtApp();
|
||||
const { $empty, $copy, $copyToClipboard, $stripHtml, $patchapi, $insertapi, $findIndex, $snackbar } = useNuxtApp();
|
||||
const radioOption = ref();
|
||||
const login = { id: 1 };
|
||||
const errors = ref([]);
|
||||
@@ -180,7 +180,7 @@ async function saveSetting() {
|
||||
detail,
|
||||
update_time: new Date(),
|
||||
};
|
||||
result = await $updateapi("usersetting", updatedSetting);
|
||||
result = await $patchapi("usersetting", updatedSetting);
|
||||
}
|
||||
isLoading.value = false;
|
||||
if (radioSave.value === "new") {
|
||||
|
||||
@@ -45,7 +45,7 @@ export default {
|
||||
if (this.setdeleted) {
|
||||
let record = await this.$getdata(name, { first: true, filter: { id } });
|
||||
record.deleted = 1;
|
||||
result = await this.$updateapi(name, record);
|
||||
result = await this.$patchapi(name, record);
|
||||
} else result = await this.$deleteapi(name, id);
|
||||
if (result === "error") return this.$dialog("Đã xảy ra lỗi, xóa dữ liệu thất bại", "Lỗi", "Error");
|
||||
this.$snackbar("Dữ liệu đã được xoá khỏi hệ thống", "Success");
|
||||
|
||||
@@ -45,7 +45,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async save() {
|
||||
let rs = await this.$updateapi("file", this.record);
|
||||
let rs = await this.$patchapi("file", this.record);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -168,7 +168,7 @@ export default {
|
||||
},
|
||||
async saveData() {
|
||||
if (!this.row) return this.insertData();
|
||||
await this.$updateapi("importsetting", this.current, undefined, this.pagename);
|
||||
await this.$patchapi("importsetting", this.current, undefined, this.pagename);
|
||||
},
|
||||
updateFromModel() {
|
||||
let filter = this.$filter(this.pagedata2.data, {
|
||||
|
||||
@@ -266,7 +266,7 @@ const store = useStore();
|
||||
const {
|
||||
$find,
|
||||
$getdata,
|
||||
$updateapi,
|
||||
$patchapi,
|
||||
$findapi,
|
||||
$getapi,
|
||||
$empty,
|
||||
@@ -361,7 +361,7 @@ async function update() {
|
||||
record.value.updater = store.login.id;
|
||||
record.value.updater_time = new Date();
|
||||
let rs = record.value.id
|
||||
? await $updateapi("people", record.value)
|
||||
? await $patchapi("people", record.value)
|
||||
: await $insertapi("people", { data: record.value, notify: false });
|
||||
if (rs === "error") return;
|
||||
if (!record.value.id) $snackbar(`Người liên quan đã được khởi tạo với mã <b>${rs.code}</b>`, "Success");
|
||||
|
||||
@@ -160,7 +160,7 @@ export default {
|
||||
});
|
||||
let rs0 = await this.$insertapi("gethash", { data: { text: this.password }, notify: false });
|
||||
user.password = rs0.rows[0];
|
||||
let rs = await this.$updateapi("user", user, undefined, false);
|
||||
let rs = await this.$patchapi("user", user, undefined, false);
|
||||
if (rs !== "error") {
|
||||
this.currpass = undefined;
|
||||
this.password = undefined;
|
||||
|
||||
@@ -53,7 +53,7 @@ export default {
|
||||
if (this.checkError()) return this.$snackbar("Mã phê duyệt gồm 4 số từ 0-9");
|
||||
let user = await this.$getdata("user", { first: true, filter: { id: this.$store.state.login.id } });
|
||||
user.approval_code = this.code;
|
||||
await this.$updateapi("user", user);
|
||||
await this.$patchapi("user", user);
|
||||
},
|
||||
checkError() {
|
||||
if (Object.keys(this.data).length < 4) return true;
|
||||
|
||||
@@ -110,7 +110,7 @@ export default {
|
||||
});
|
||||
let rs = await this.$insertapi("gethash", { data: { text: this.password } });
|
||||
user.password = rs.rows[0];
|
||||
let rs1 = await this.$updateapi("user", user);
|
||||
let rs1 = await this.$patchapi("user", user);
|
||||
if (rs1 !== "error") this.$emit("close");
|
||||
else {
|
||||
this.$snackbar("Có lỗi xảy ra. Hãy thử lại một lần nữa", "Error");
|
||||
|
||||
@@ -1134,7 +1134,6 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
return apisWithReady;
|
||||
};
|
||||
|
||||
// get data
|
||||
const getapi = async function (list) {
|
||||
try {
|
||||
const arr = list.map((v) => {
|
||||
@@ -1159,7 +1158,6 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
}
|
||||
};
|
||||
|
||||
// insert data
|
||||
const insertapi = async function (name, { data, values, notify = true } = {}) {
|
||||
try {
|
||||
const api = findapi(name);
|
||||
@@ -1206,64 +1204,43 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
}
|
||||
};
|
||||
|
||||
// update api
|
||||
const updateapi = async function (name, data, values, notify) {
|
||||
try {
|
||||
let found = findapi(name);
|
||||
let curpath = found.path ? paths.find((x) => x.name === found.path).url : path;
|
||||
let updateUrl = found.url_detail ? found.url_detail : found.url;
|
||||
let rs = await $fetch(`${curpath}${updateUrl}${data.id}/`, {
|
||||
method: "PUT",
|
||||
body: data,
|
||||
params: { values: values || found.params.values },
|
||||
});
|
||||
if (found.commit) {
|
||||
let index = $store[found.commit] ? $store[found.commit].findIndex((v) => v.id === rs.id) : -1;
|
||||
if (index >= 0) {
|
||||
var copy = $copy($store[found.commit]);
|
||||
if (Array.isArray(rs) === false) copy[index] = rs;
|
||||
else {
|
||||
rs.forEach((v) => {
|
||||
let index = copy.findIndex((v) => v.id === v.id);
|
||||
if (index >= 0) copy[index] = v;
|
||||
});
|
||||
}
|
||||
$store.commit(found.commit, copy);
|
||||
}
|
||||
}
|
||||
if (notify !== false) {
|
||||
$store.lang === "en"
|
||||
? $snackbar("Data has been successfully saved to the system.", "Success")
|
||||
: $snackbar("Dữ liệu đã được lưu vào hệ thống", "Success");
|
||||
}
|
||||
return rs;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
return "error";
|
||||
}
|
||||
};
|
||||
|
||||
// patch api
|
||||
const patchapi = async function (name, data, values, notify) {
|
||||
try {
|
||||
let found = findapi(name);
|
||||
let curpath = found.path ? paths.find((x) => x.name === found.path).url : path;
|
||||
let updateUrl = found.url_detail ? found.url_detail : found.url;
|
||||
const api = findapi(name);
|
||||
const curpath = api.path ? paths.find((x) => x.name === api.path).url : path;
|
||||
const updateUrl = api.url_detail || api.url;
|
||||
|
||||
const rs = await $fetch(`${curpath}${updateUrl}${data.id}/`, {
|
||||
method: "PATCH",
|
||||
body: data,
|
||||
params: { values: values || found.params?.values },
|
||||
params: { values: values || api.params?.values },
|
||||
});
|
||||
|
||||
if (notify !== false) {
|
||||
$store.lang === "en"
|
||||
? $snackbar("Data has been successfully saved to the system.", "Success")
|
||||
: $snackbar("Dữ liệu đã được lưu vào hệ thống", "Success");
|
||||
if (api.commit) {
|
||||
const index = $store[api.commit] ? $store[api.commit].findIndex((v) => v.id === rs.id) : -1;
|
||||
if (index >= 0) {
|
||||
const copy = $copy($store[api.commit]);
|
||||
if (Array.isArray(rs)) {
|
||||
rs.forEach((r) => {
|
||||
const index = copy.findIndex((v) => v.id === r.id);
|
||||
if (index >= 0) copy[index] = r;
|
||||
});
|
||||
} else {
|
||||
copy[index] = rs;
|
||||
}
|
||||
$store.commit(api.commit, copy);
|
||||
}
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
$snackbar(
|
||||
$store.lang === "en" ? "Data has been successfully saved to the system." : "Dữ liệu đã được lưu vào hệ thống",
|
||||
"Success",
|
||||
);
|
||||
}
|
||||
return rs;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
console.error(err);
|
||||
return "error";
|
||||
}
|
||||
};
|
||||
@@ -1335,10 +1312,10 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
};
|
||||
|
||||
const getdata = async function (name, { filter, params, first = false } = {}) {
|
||||
const found = findapi(name);
|
||||
if (params) found.params = params;
|
||||
else if (filter) found.params.filter = filter;
|
||||
const rs = await getapi([found]);
|
||||
const api = findapi(name);
|
||||
if (params) api.params = params;
|
||||
else if (filter) api.params.filter = filter;
|
||||
const rs = await getapi([api]);
|
||||
const { data } = rs[0];
|
||||
if (data) {
|
||||
if (data.rows) {
|
||||
@@ -1394,7 +1371,6 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
subscribeToData(payload, callback);
|
||||
};
|
||||
|
||||
// insert row
|
||||
const insertrow = async function (name, data, values, pagename, notify) {
|
||||
let result = await insertapi(name, { data, values, notify });
|
||||
if (result === "error" || !pagename || !$store[pagename]) return result;
|
||||
@@ -1404,18 +1380,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// update row
|
||||
const updaterow = async function (name, data, values, pagename, notify) {
|
||||
let result = await updateapi(name, data, values, notify);
|
||||
if (result === "error" || !pagename || !$store[pagename]) return result;
|
||||
let copy = $clone($store[pagename]);
|
||||
copy.update = { refresh: true };
|
||||
$store.commit(pagename, copy);
|
||||
return result;
|
||||
};
|
||||
|
||||
// patch row
|
||||
const patchrow = async function (name, data, values, pagename, notify) {
|
||||
let result = await patchapi(name, data, values, notify);
|
||||
if (result === "error" || !pagename || !$store[pagename]) return result;
|
||||
let copy = $clone($store[pagename]);
|
||||
@@ -1683,7 +1648,6 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
getdata,
|
||||
subscribe,
|
||||
insertapi,
|
||||
updateapi,
|
||||
patchapi,
|
||||
updaterow,
|
||||
findpage,
|
||||
|
||||
Reference in New Issue
Block a user