123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import request from "@/utils/axiosReq";
- import { CommonQueryResult } from "~/common";
- export function Query<T = any>(params): Promise<CommonQueryResult<T>> {
- if (NEW_DATACONTENT_ID.includes(params.id)) {
- return NewQuery<T>(params);
- }
- return request({
- url: "/openApi/query",
- method: "post",
- data: params,
- });
- }
- function NewQuery<T = any>(params): Promise<CommonQueryResult<T>> {
- return request({
- url: "/newOpenApi/search",
- method: "post",
- data: params,
- });
- }
- export async function myQuery(id, ...dataContent) {
- const params = {
- id,
- dataContent,
- };
- try {
- const result = await Query(params);
- if (Number(result.code) === 0) {
- return result.returnData.listValues;
- } else {
- return Promise.reject(result.message);
- }
- } catch (error) {
- return Promise.reject(error);
- }
- }
- export async function htQuery(id, ...dataContent) {
- const params = {
- id,
- dataContent,
- };
- try {
- const result = await Query(params);
- if (Number(result.code) === 0) {
- return result.returnData;
- } else {
- return [];
- }
- } catch (error) {
- return [];
- }
- }
- export function GeneralDataReception(params): Promise<CommonQueryResult> {
- return request({
- url: "/openApi/generalDataReception",
- method: "post",
- data: params,
- });
- }
- //增/删/改
- export async function dataToChange(
- id: number,
- data: any,
- event: number,
- key?: string
- ) {
- try {
- const params = {
- serviceId: id,
- dataContent: formatChange(data, event, key),
- event: `${event}`,
- // authId: this.AauthId
- };
- const { code, message } =
- event == 1
- ? await newData(params)
- : event == 2
- ? await modifyData(params)
- : await moveData(params);
- return { code, message };
- } catch (error) {
- return { code: 1, message: error };
- }
- }
- //新增
- function newData(params) {
- return request({
- url: "/externalApi/openApi/sendData",
- method: "post",
- data: params,
- });
- }
- //修改
- function modifyData(params) {
- return request({
- url: "/externalApi/openApi/sendData",
- method: "post",
- data: params,
- });
- }
- //删除movedata
- function moveData(params) {
- return request({
- url: "/externalApi/openApi/sendData",
- method: "post",
- data: params,
- });
- }
- function formatChange(data, event, key) {
- const datas: any = [];
- const flag = Array.isArray(data);
- if (flag) {
- for (let i = 0; i < data.length; i++) {
- let obj: any = {};
- if (event == 1) {
- obj.Value = data[i];
- } else if (event == 2) {
- obj.Value = data[i];
- obj.filter = {};
- if (Array.isArray(key)) {
- const keys = <any>[];
- const vals = <any>[];
- obj.filter = [];
- for (let j = 0; j < key.length; j++) {
- const dep = key[i];
- keys.push(Object.keys(dep));
- vals.push(Object.values(dep));
- }
- const nobj = {
- left: "(",
- column: `${keys[i]}`,
- comparator: "=",
- value: `${vals[i]}`,
- right: ")",
- connector: "and",
- };
- obj.filter.push(nobj);
- if (obj.Value.hasOwnProperty(keys[i])) {
- delete obj.Value[keys[i]];
- }
- } else {
- obj.filter[key] = data[i][key];
- if (obj.Value[key]) {
- delete obj.Value[key];
- }
- }
- } else {
- obj = data[i];
- }
- datas.push(obj);
- }
- } else {
- let obj: any = {};
- if (event == 1) {
- obj.Value = data;
- } else if (event == 2) {
- obj.Value = data;
- obj.filter = [
- {
- left: "(",
- column: `${key}`,
- comparator: "=",
- value: `${data[key]}`,
- right: ")",
- connector: "and",
- },
- ];
- if (obj.Value[key]) {
- delete obj.Value[key];
- }
- } else {
- obj = data;
- }
- datas.push(obj);
- }
- return datas;
- }
|