publicFunc.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import { Query, newData, modifyData, moveData } from "@/api/webApi"
  2. import { getAuthData } from "@/utils/validate";
  3. export default {
  4. data () {
  5. return {
  6. AauthId: null,
  7. AqueryId: null,
  8. AauthTable: [],
  9. TauthId: null,
  10. TqueryId: null,
  11. AqueryParams: null
  12. }
  13. },
  14. created () {
  15. const { auth_id } = this.$route.meta
  16. if (auth_id) {
  17. const { arrs } = getAuthData(auth_id)
  18. const table = arrs.filter(item => item.auth_type == 4)
  19. const table2 = arrs.filter(item => item.auth_type == 5)
  20. if (table2 && table2.length) {
  21. const obj = table2[0]
  22. this.AqueryParams = obj
  23. this.TqueryId = obj.queryTemplateID
  24. this.TauthId = obj.auth_id
  25. }
  26. if (table && table.length) {
  27. if (table.length == 1) {
  28. const obj = table[0]
  29. this.AqueryParams = obj
  30. this.AqueryId = obj.queryTemplateID
  31. this.AauthId = obj.auth_id
  32. } else {
  33. this.AauthTable = table
  34. }
  35. } else {
  36. this.AauthId = auth_id
  37. this.AqueryId = auth_id
  38. }
  39. }
  40. },
  41. methods: {
  42. formatQuery (arrs, key = '') {
  43. const params = []
  44. if (key) {
  45. const flag = Array.isArray(arrs)
  46. if (flag) {
  47. for (let i = 0; i < arrs.length; i++) {
  48. const obj = {
  49. "left": "(",
  50. "column": `${key[i]}`,
  51. "comparator": "=",
  52. "value": `${arrs[i][key[i]]}`,
  53. "right": ")",
  54. "connector": "and"
  55. }
  56. params.push(obj)
  57. }
  58. } else {
  59. params.push({
  60. "left": "(",
  61. "column": `${key}`,
  62. "comparator": "=",
  63. "value": `${arrs[key]}`,
  64. "right": ")",
  65. "connector": "and"
  66. })
  67. }
  68. } else {
  69. params.push({
  70. "left": "(",
  71. "column": ``,
  72. "comparator": "=",
  73. "value": ``,
  74. "right": ")",
  75. "connector": "and"
  76. })
  77. }
  78. return params
  79. },
  80. formatChange (data, event, key) {
  81. const datas = []
  82. const flag = Array.isArray(data)
  83. if (flag) {
  84. for (let i = 0; i < data.length; i++) {
  85. let obj = {}
  86. if (event == 1) {
  87. obj.Value = data[i]
  88. } else if (event == 2) {
  89. obj.Value = data[i]
  90. obj.filter = {}
  91. if (Array.isArray(key)) {
  92. const keys = []
  93. const vals = []
  94. obj.filter = []
  95. for (let j = 0; j < key.length; j++) {
  96. const dep = key[i]
  97. keys.push(Object.keys(dep))
  98. vals.push(Object.values(dep))
  99. }
  100. const nobj = {
  101. "left": "(",
  102. "column": `${keys[i]}`,
  103. "comparator": "=",
  104. "value": `${vals[i]}`,
  105. "right": ")",
  106. "connector": "and"
  107. }
  108. obj.filter.push(nobj)
  109. if (obj.Value.hasOwnProperty(keys[i])) {
  110. delete obj.Value[keys[i]]
  111. }
  112. } else {
  113. obj.filter[key] = data[i][key]
  114. if (obj.Value[key]) {
  115. delete obj.Value[key]
  116. }
  117. }
  118. } else {
  119. obj = data[i]
  120. }
  121. datas.push(obj)
  122. }
  123. } else {
  124. let obj = {}
  125. if (event == 1) {
  126. obj.Value = data
  127. } else if (event == 2) {
  128. obj.Value = data
  129. obj.filter = [{
  130. "left": "(",
  131. "column": `${key}`,
  132. "comparator": "=",
  133. "value": `${data[key]}`,
  134. "right": ")",
  135. "connector": "and"
  136. }]
  137. if (obj.Value[key]) {
  138. delete obj.Value[key]
  139. }
  140. } else {
  141. obj = data
  142. }
  143. datas.push(obj)
  144. }
  145. return datas
  146. },
  147. //查询
  148. async getQueryList (id, dataContent = {}, pageIndex = 1, pageSize = 999) {
  149. try {
  150. const { code, rowcount, returnData } = await Query({
  151. serviceId: id,
  152. page: pageIndex,
  153. pageSize: pageSize,
  154. dataContent: dataContent,
  155. event: '0',
  156. // authId: this.AauthId
  157. })
  158. return { code, rowcount, returnData }
  159. } catch (error) {
  160. return []
  161. }
  162. },
  163. //权限查询
  164. async getQueryListAuth (id, dataContent = {}, pageIndex = 1, pageSize = 999, authId) {
  165. try {
  166. const { code, rowcount, returnData } = await Query({
  167. serviceId: id,
  168. page: pageIndex,
  169. pageSize: pageSize,
  170. dataContent: dataContent,
  171. event: '0',
  172. authId: authId ?? this.AauthId
  173. })
  174. return { code, rowcount, returnData }
  175. } catch (error) {
  176. return []
  177. }
  178. },
  179. //高级查询
  180. async getQueryGj (id, dataContent = {}, key, pageSize) {
  181. try {
  182. const { code, columnset, returnData } = await Query({
  183. serviceId: id,
  184. page: this.pageIndex,
  185. pageSize: pageSize ?? this.pageSize,
  186. dataContent: this.formatQuery(dataContent, key),
  187. event: '0',
  188. // authId: this.AauthId
  189. })
  190. if (code == 0) {
  191. return returnData
  192. } else {
  193. return []
  194. }
  195. } catch (error) {
  196. return []
  197. }
  198. },
  199. //增/删/改
  200. async getChangeList (id, data, event, key) {
  201. try {
  202. const params = {
  203. serviceId: id,
  204. dataContent: this.formatChange(data, event, key),
  205. event: `${event}`,
  206. // authId: this.AauthId
  207. };
  208. const { code, message } =
  209. event == 1
  210. ? await newData(params)
  211. : event == 2
  212. ? await modifyData(params)
  213. : await moveData(params);
  214. return { code, message }
  215. } catch (error) {
  216. console.log(error)
  217. return 0
  218. }
  219. },
  220. tipMsg (code, msg) {
  221. if (code == 0 || code) {
  222. this.$message.success(msg ?? '操作成功')
  223. } else {
  224. this.$message.error(msg ?? '操作失败')
  225. }
  226. }
  227. }
  228. }