webApi.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import request from "@/utils/axiosReq";
  2. import { CommonQueryResult } from "~/common";
  3. export function Query<T = any>(params): Promise<CommonQueryResult<T>> {
  4. if (NEW_DATACONTENT_ID.includes(params.id)) {
  5. return NewQuery<T>(params);
  6. }
  7. return request({
  8. url: "/openApi/query",
  9. method: "post",
  10. data: params,
  11. });
  12. }
  13. function NewQuery<T = any>(params): Promise<CommonQueryResult<T>> {
  14. return request({
  15. url: "/newOpenApi/search",
  16. method: "post",
  17. data: params,
  18. });
  19. }
  20. export async function myQuery(id, ...dataContent) {
  21. const params = {
  22. id,
  23. dataContent,
  24. };
  25. try {
  26. const result = await Query(params);
  27. if (Number(result.code) === 0) {
  28. return result.returnData.listValues;
  29. } else {
  30. return Promise.reject(result.message);
  31. }
  32. } catch (error) {
  33. return Promise.reject(error);
  34. }
  35. }
  36. export async function htQuery(id, ...dataContent) {
  37. const params = {
  38. id,
  39. dataContent,
  40. };
  41. try {
  42. const result = await Query(params);
  43. if (Number(result.code) === 0) {
  44. return result.returnData;
  45. } else {
  46. return [];
  47. }
  48. } catch (error) {
  49. return [];
  50. }
  51. }
  52. export function GeneralDataReception(params): Promise<CommonQueryResult> {
  53. return request({
  54. url: "/openApi/generalDataReception",
  55. method: "post",
  56. data: params,
  57. });
  58. }
  59. //增/删/改
  60. export async function dataToChange(
  61. id: number,
  62. data: any,
  63. event: number,
  64. key?: string
  65. ) {
  66. try {
  67. const params = {
  68. serviceId: id,
  69. dataContent: formatChange(data, event, key),
  70. event: `${event}`,
  71. // authId: this.AauthId
  72. };
  73. const { code, message } =
  74. event == 1
  75. ? await newData(params)
  76. : event == 2
  77. ? await modifyData(params)
  78. : await moveData(params);
  79. return { code, message };
  80. } catch (error) {
  81. return { code: 1, message: error };
  82. }
  83. }
  84. //新增
  85. function newData(params) {
  86. return request({
  87. url: "/externalApi/openApi/sendData",
  88. method: "post",
  89. data: params,
  90. });
  91. }
  92. //修改
  93. function modifyData(params) {
  94. return request({
  95. url: "/externalApi/openApi/sendData",
  96. method: "post",
  97. data: params,
  98. });
  99. }
  100. //删除movedata
  101. function moveData(params) {
  102. return request({
  103. url: "/externalApi/openApi/sendData",
  104. method: "post",
  105. data: params,
  106. });
  107. }
  108. function formatChange(data, event, key) {
  109. const datas: any = [];
  110. const flag = Array.isArray(data);
  111. if (flag) {
  112. for (let i = 0; i < data.length; i++) {
  113. let obj: any = {};
  114. if (event == 1) {
  115. obj.Value = data[i];
  116. } else if (event == 2) {
  117. obj.Value = data[i];
  118. obj.filter = {};
  119. if (Array.isArray(key)) {
  120. const keys = <any>[];
  121. const vals = <any>[];
  122. obj.filter = [];
  123. for (let j = 0; j < key.length; j++) {
  124. const dep = key[i];
  125. keys.push(Object.keys(dep));
  126. vals.push(Object.values(dep));
  127. }
  128. const nobj = {
  129. left: "(",
  130. column: `${keys[i]}`,
  131. comparator: "=",
  132. value: `${vals[i]}`,
  133. right: ")",
  134. connector: "and",
  135. };
  136. obj.filter.push(nobj);
  137. if (obj.Value.hasOwnProperty(keys[i])) {
  138. delete obj.Value[keys[i]];
  139. }
  140. } else {
  141. obj.filter[key] = data[i][key];
  142. if (obj.Value[key]) {
  143. delete obj.Value[key];
  144. }
  145. }
  146. } else {
  147. obj = data[i];
  148. }
  149. datas.push(obj);
  150. }
  151. } else {
  152. let obj: any = {};
  153. if (event == 1) {
  154. obj.Value = data;
  155. } else if (event == 2) {
  156. obj.Value = data;
  157. obj.filter = [
  158. {
  159. left: "(",
  160. column: `${key}`,
  161. comparator: "=",
  162. value: `${data[key]}`,
  163. right: ")",
  164. connector: "and",
  165. },
  166. ];
  167. if (obj.Value[key]) {
  168. delete obj.Value[key];
  169. }
  170. } else {
  171. obj = data;
  172. }
  173. datas.push(obj);
  174. }
  175. return datas;
  176. }