detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <view class="dynamicModel-form-v jnpf-wrap jnpf-wrap-form" v-if="showPage">
  3. <Parser :formConf="formConf" :formData="formData" ref="dynamicForm" v-if="!loading" :key="key"
  4. @toDetail="toDetail" />
  5. <view class="u-m-t-20 dataLog-box u-flex-col u-m-b-20" v-if="formConf.dataLog && !setting.noDataLog">
  6. <view class="title u-flex">
  7. <u-icon name=" icon-ym-generator-menu" custom-prefix="icon-ym"></u-icon>
  8. <text class="u-m-l-10">修改记录</text>
  9. </view>
  10. <view class="dataLog-v" v-if="dataLogList.length">
  11. <dataLog :dataLogList="dataLogList"></dataLog>
  12. </view>
  13. <NoData v-else paddingTop="0" backgroundColor="#fff" zIndex="9"></NoData>
  14. </view>
  15. <view class="buttom-actions">
  16. <CustomButton class="u-flex buttom-btn-left-inner" v-if="showMoreBtn" btnText="更多" btnType="more"
  17. iconName="more-dot-fill" size="28" @handleBtn="showAction = $event" :btnLoading="loading" />
  18. <template v-if="showEditBtn">
  19. <CustomButton class="u-flex buttom-btn-left-inner" :btnText="$t('common.cancelText')"
  20. btnIcon="icon-ym icon-ym-add-cancel" customIcon :btnLoading="loading" />
  21. <u-button class="buttom-btn" type="primary" @click.stop="handleEdit" :loading="loading">
  22. {{labelS.btn_edit}}
  23. </u-button>
  24. </template>
  25. <u-button class="cancel" @click.stop="jnpf.goBack()"
  26. v-if="!showEditBtn && !showMoreBtn">{{$t('common.cancelText')}}</u-button>
  27. </view>
  28. <u-select :list="actionList" v-model="showAction" @confirm="selectBtnconfirm" />
  29. </view>
  30. </template>
  31. <script>
  32. import NoData from '@/components/noData'
  33. import CustomButton from '@/components/CustomButton'
  34. import {
  35. getConfigData,
  36. getOnlineLog,
  37. getModelInfo,
  38. getDataChange,
  39. launchFlow
  40. } from "@/api/apply/visualDev";
  41. import {
  42. getRelationFormDetail,
  43. getDataInterfaceRes
  44. } from "@/api/common.js";
  45. import Parser from "./components/detail/Parser";
  46. import dataLog from '@/components/dataLog'
  47. import deepClone from '../../../uni_modules/vk-uview-ui/libs/function/deepClone';
  48. export default {
  49. components: {
  50. Parser,
  51. dataLog,
  52. NoData,
  53. CustomButton
  54. },
  55. data() {
  56. return {
  57. dataLogList: [],
  58. actionList: [],
  59. showAction: false,
  60. showPage: false,
  61. loading: true,
  62. isPreview: "0",
  63. modelId: "",
  64. formConf: {},
  65. formData: {},
  66. dataForm: {
  67. id: "",
  68. data: "",
  69. },
  70. btnType: "",
  71. formPermissionList: {},
  72. formList: [],
  73. labelS: {}
  74. };
  75. },
  76. onLoad(option) {
  77. uni.setNavigationBarTitle({
  78. title: this.$t('common.detailText')
  79. })
  80. let config = JSON.parse(this.jnpf.base64.decode(option.config));
  81. this.formPermissionList = !config.currentMenu ? [] :
  82. JSON.parse(decodeURIComponent(config.currentMenu));
  83. this.formList = this.formPermissionList.formList;
  84. this.btnType = config.btnType || "";
  85. this.labelS = config.labelS || {
  86. btn_edit: this.$t('common.editText')
  87. }
  88. this.modelId = config.modelId;
  89. this.isPreview = config.isPreview || "0";
  90. this.dataForm.id = config.id || "";
  91. this.setting = config;
  92. this.getConfigData();
  93. uni.$on("refresh", () => {
  94. this.getConfigData();
  95. });
  96. },
  97. computed: {
  98. showMoreBtn() {
  99. if (this.actionList.length && !this.setting?.noShowBtn || 0 && this.setting?.noDataLog) return true
  100. return false
  101. },
  102. showEditBtn() {
  103. if (this.btnType === 'btn_edit' && !this.setting.noShowBtn && this.setting.enableEdit) return true
  104. return false
  105. }
  106. },
  107. onShow() {
  108. setTimeout(() => {
  109. uni.$emit('initCollapse')
  110. }, 100)
  111. },
  112. onUnload() {
  113. uni.$off("refresh");
  114. },
  115. methods: {
  116. // 自定义按钮事件
  117. selectBtnconfirm(e) {
  118. var i = this.actionList.findIndex((item) => {
  119. return item.value == e[0].value
  120. })
  121. const item = this.actionList[i].actionConfig
  122. const row = this.formData
  123. // 自定义启用规则判断
  124. if (item.btnType == 1) this.handlePopup(item, row)
  125. if (item.btnType == 2) this.handleScriptFunc(item, row)
  126. if (item.btnType == 3) this.handleInterface(item, row)
  127. if (item.btnType == 4) this.handleLaunchFlow(item, [row])
  128. },
  129. //自定义按钮发起流程
  130. handleLaunchFlow(item, records) {
  131. const data = deepClone(item.launchFlow)
  132. let dataList = [];
  133. for (let i = 0; i < records.length; i++) {
  134. dataList.push(this.jnpf.getLaunchFlowParamList(data.transferList, records[i], this.getRowKey));
  135. }
  136. const query = {
  137. template: data.flowId,
  138. btnCode: item.value,
  139. currentUser: data.currentUser,
  140. customUser: data.customUser,
  141. initiator: data.initiator,
  142. dataList
  143. };
  144. launchFlow(query, this.modelId).then(res => {
  145. this.$u.toast(res.msg)
  146. });
  147. },
  148. //自定义按钮弹窗操作
  149. handlePopup(item, row) {
  150. let data = {
  151. config: item,
  152. modelId: this.modelId,
  153. id: row.id,
  154. row,
  155. }
  156. data = encodeURIComponent(JSON.stringify(data))
  157. uni.navigateTo({
  158. url: '/pages/apply/customBtn/index?data=' + data
  159. })
  160. },
  161. //自定义按钮JS操作
  162. handleScriptFunc(item, row) {
  163. const parameter = {
  164. data: row,
  165. refresh: this.initData,
  166. onlineUtils: this.jnpf.onlineUtils,
  167. }
  168. const func = this.jnpf.getScriptFunc.call(this, item.func)
  169. if (!func) return
  170. func.call(this, parameter)
  171. },
  172. //自定义按钮接口操作
  173. handleInterface(item, row, index) {
  174. const handlerData = () => {
  175. getModelInfo(this.modelId, row.id).then(res => {
  176. const dataForm = res.data || {};
  177. if (!dataForm.data) return;
  178. const data = {
  179. ...JSON.parse(dataForm.data),
  180. id: row.id
  181. };
  182. handlerInterface(data);
  183. })
  184. }
  185. const handlerInterface = (data) => {
  186. let query = {
  187. paramList: this.jnpf.getParamList(item.templateJson, data) || [],
  188. }
  189. getDataInterfaceRes(item.interfaceId, query).then(res => {
  190. uni.showToast({
  191. title: res.msg,
  192. icon: 'none'
  193. })
  194. if (item.isRefresh) this.initData();
  195. })
  196. }
  197. const handleFun = () => {
  198. handlerData();
  199. };
  200. if (!item.useConfirm) return handleFun()
  201. uni.showModal({
  202. title: '提示',
  203. content: item.confirmTitle || '确认执行此操作',
  204. success: (res) => {
  205. if (!res.cancel) handleFun()
  206. }
  207. })
  208. },
  209. getOnlineLog() {
  210. getOnlineLog(this.setting.modelId, this.setting.id).then(res => {
  211. this.dataLogList = res.data.list || []
  212. })
  213. },
  214. getConfigData() {
  215. this.loading = true;
  216. getConfigData(this.modelId).then((res) => {
  217. if (res.code !== 200 || !res.data) {
  218. uni.showToast({
  219. title: "暂无此页面",
  220. icon: "none",
  221. complete: () => {
  222. setTimeout(() => {
  223. uni.navigateBack();
  224. }, 1500);
  225. },
  226. });
  227. return;
  228. }
  229. this.formConf = res.data.formData ? JSON.parse(res.data.formData) : {};
  230. this.actionList = this.formConf?.customBtns || []
  231. this.actionList.map((o) => {
  232. if (o.labelI18nCode) o.label = this.$t(o.labelI18nCode, o.label)
  233. })
  234. this.beforeInit(this.formConf.fields || []);
  235. this.showPage = true;
  236. this.key = +new Date();
  237. this.initData();
  238. });
  239. },
  240. beforeInit(fields) {
  241. const loop = (list) => {
  242. for (var index = 0; index < list.length; index++) {
  243. const config = list[index].__config__;
  244. if (config.children && config.children.length) loop(config.children);
  245. if (config.jnpfKey == "tableGrid") {
  246. let newList = [];
  247. for (var i = 0; i < config.children.length; i++) {
  248. let element = config.children[i];
  249. for (var j = 0; j < element.__config__.children.length; j++) {
  250. let item = element.__config__.children[j];
  251. newList.push(...item.__config__.children);
  252. }
  253. }
  254. list.splice(index, 1, ...newList);
  255. }
  256. }
  257. };
  258. loop(fields);
  259. },
  260. initData() {
  261. this.$nextTick(() => {
  262. if (this.dataForm.id) {
  263. let extra = {
  264. modelId: this.modelId,
  265. id: this.dataForm.id,
  266. type: 2,
  267. };
  268. uni.setStorageSync('dynamicModelExtra', extra)
  269. this.getRelationFormDetail()
  270. } else {
  271. this.loading = false;
  272. }
  273. this.$nextTick(() => {
  274. this.getOnlineLog()
  275. })
  276. this.key = +new Date();
  277. });
  278. },
  279. getRelationFormDetail() {
  280. const processResponse = (res) => {
  281. this.dataForm = res.data;
  282. this.loading = false;
  283. if (!this.dataForm.data) return;
  284. this.formData = {
  285. ...JSON.parse(this.dataForm.data),
  286. id: this.dataForm.id,
  287. };
  288. this.fillFormData(this.formConf, this.formData);
  289. this.initRelationForm(this.formConf.fields);
  290. };
  291. let requestParams = {
  292. id: this.dataForm.id
  293. };
  294. if (this.setting?.sourceRelationForm) {
  295. if (this.setting.propsValue) requestParams.propsValue = this.setting.propsValue;
  296. }
  297. getDataChange(requestParams, this.modelId).then(res => {
  298. processResponse(res)
  299. }).catch(err => {
  300. this.loading = false;
  301. })
  302. },
  303. fillFormData(form, data) {
  304. const loop = (list, parent) => {
  305. for (let i = 0; i < list.length; i++) {
  306. let item = list[i];
  307. if (item.__vModel__) {
  308. if (
  309. item.__config__.jnpfKey === "relationForm" ||
  310. item.__config__.jnpfKey === "popupSelect"
  311. ) {
  312. item.__config__.defaultValue = data[item.__vModel__ + "_id"];
  313. this.$set(item, "name", item.__config__.defaultValue || "");
  314. } else {
  315. let val = data.hasOwnProperty(item.__vModel__) ?
  316. data[item.__vModel__] :
  317. item.__config__.defaultValue;
  318. item.__config__.defaultValue = val;
  319. }
  320. if (this.formPermissionList.useFormPermission) {
  321. let id = item.__config__.isSubTable ?
  322. parent.__vModel__ + "-" + item.__vModel__ :
  323. item.__vModel__;
  324. let noShow = true;
  325. if (this.formList && this.formList.length) {
  326. noShow = !this.formList.some((o) => o.enCode === id);
  327. }
  328. noShow = item.__config__.noShow ? item.__config__.noShow : noShow;
  329. this.$set(item.__config__, "noShow", noShow);
  330. }
  331. } else {
  332. if (['relationFormAttr', 'popupAttr'].includes(item.__config__.jnpfKey)) {
  333. item.__config__.defaultValue =
  334. data[item.relationField.split('_jnpfTable_')[0] + '_' + item.showField];
  335. }
  336. }
  337. if (
  338. item.__config__ &&
  339. item.__config__.children &&
  340. Array.isArray(item.__config__.children)
  341. ) {
  342. loop(item.__config__.children, item);
  343. }
  344. }
  345. };
  346. loop(form.fields);
  347. this.loading = false;
  348. },
  349. initRelationForm(componentList) {
  350. componentList.forEach((cur) => {
  351. const config = cur.__config__;
  352. if (
  353. config.jnpfKey == "relationFormAttr" ||
  354. config.jnpfKey == "popupAttr"
  355. ) {
  356. const relationKey = cur.relationField.split("_jnpfTable_")[0];
  357. componentList.forEach((item) => {
  358. const noVisibility =
  359. Array.isArray(item.__config__.visibility) &&
  360. !item.__config__.visibility.includes("app");
  361. if (
  362. relationKey == item.__vModel__ &&
  363. (noVisibility || !!item.__config__.noShow) && !cur.__vModel__
  364. ) {
  365. cur.__config__.noShow = true;
  366. }
  367. });
  368. }
  369. if (cur.__config__.children && cur.__config__.children.length)
  370. this.initRelationForm(cur.__config__.children);
  371. });
  372. },
  373. toDetail(item) {
  374. const id = item.__config__.defaultValue;
  375. if (!id) return;
  376. let config = {
  377. modelId: item.modelId,
  378. id: id,
  379. formTitle: "详情",
  380. noShowBtn: 1,
  381. noDataLog: 1,
  382. sourceRelationForm: item?.sourceRelationForm || false,
  383. propsValue: item?.propsValue || ''
  384. };
  385. this.$nextTick(() => {
  386. const url =
  387. "/pages/apply/dynamicModel/detail?config=" +
  388. this.jnpf.base64.encode(JSON.stringify(config));
  389. uni.navigateTo({
  390. url: url,
  391. });
  392. });
  393. },
  394. handleEdit() {
  395. if (this.setting.disableEdit) return;
  396. const currentMenu = encodeURIComponent(JSON.stringify(this.formPermissionList));
  397. let config = {
  398. modelId: this.modelId,
  399. isPreview: this.isPreview,
  400. id: this.setting.id,
  401. btnType: "btn_edit",
  402. currentMenu,
  403. list: this.setting.list,
  404. index: this.setting.index,
  405. };
  406. const url =
  407. "/pages/apply/dynamicModel/form?config=" +
  408. this.jnpf.base64.encode(JSON.stringify(config));
  409. uni.navigateTo({
  410. url: url,
  411. });
  412. },
  413. },
  414. };
  415. </script>
  416. <style lang="scss" scoped>
  417. page {
  418. background-color: #f0f2f6;
  419. }
  420. </style>