index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view>
  3. <uni-nav-bar :fixed="true" :statusBar="true" :border="false" height="44">
  4. <view class="nav-left">
  5. <view class="nav-left-text">{{config.fullName}}</view>
  6. </view>
  7. </uni-nav-bar>
  8. <view v-if="!showPsd">
  9. <template v-if="type==='form' || type==='list' || type === 'detail'">
  10. <view v-if="type==='form' || type === 'detail'">
  11. <view class="jnpf-wrap jnpf-wrap-form" v-if="!loading && (type==='form' || type === 'detail')">
  12. <JnpfParser :formConf="formConf" :isShortLink="true" ref="dynamicForm" @submit="sumbitForm"
  13. :key="newDate" />
  14. <view class="buttom-actions" v-if="type==='form'">
  15. <u-button class="buttom-btn" @click.stop="resetForm">重置</u-button>
  16. <u-button class="buttom-btn" type="primary" @click.stop="submit" :loading="btnLoading">
  17. {{formConf.confirmButtonText||'确定'}}
  18. </u-button>
  19. </view>
  20. <view class="buttom-actions" v-if="type==='detail'">
  21. <u-button class="buttom-btn" @click.stop="resetForm">取消</u-button>
  22. </view>
  23. </view>
  24. </view>
  25. <view v-if="type==='list' && flg">
  26. <List ref="List" :config="config" :modelId="modelId" :columnText="columnText"
  27. :columnCondition="columnCondition" :encryption='encryption' />
  28. </view>
  29. </template>
  30. </view>
  31. <view v-show="!showPsd"></view>
  32. <u-modal v-model="showPsd" :title-style="titleStyle" title="密码" @confirm="confirm" v-if="showPsd">
  33. <view class="slot-content u-p-l-32 u-p-r-22 u-p-t-20 u-p-b-20">
  34. <u-input type="password" placeholder="请输入密码" :border="true" v-model="password" />
  35. </view>
  36. </u-modal>
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. getConfig,
  42. createModel,
  43. getShortLink,
  44. checkPwd
  45. } from '@/api/apply/webDesign'
  46. import md5Libs from "/uni_modules/vk-uview-ui/libs/function/md5";
  47. import List from './list.vue'
  48. const getFormDataFields = item => {
  49. const config = item.__config__
  50. if (!config || !config.jnpfKey) return true
  51. const jnpfKey = config.jnpfKey
  52. const list = ["input", "textarea", "inputNumber", "switch", "datePicker", "timePicker", "colorPicker", "rate",
  53. "slider", "editor", "link", "text", "alert", 'table', "collapse", 'collapseItem', 'tabItem',
  54. "tab", "row", "card", "groupTitle", "divider", 'location', 'stepItem', 'steps'
  55. ]
  56. const fieldsSelectList = ["radio", "checkbox", "select", "cascader", "treeSelect"]
  57. if (list.includes(jnpfKey) || (fieldsSelectList.includes(jnpfKey) && config.dataType === 'static')) return true
  58. return false
  59. }
  60. export default {
  61. components: {
  62. List
  63. },
  64. data() {
  65. return {
  66. columnCondition: [],
  67. columnText: [],
  68. flg: false,
  69. password: '',
  70. titleStyle: {
  71. paddingTop: '24rpx'
  72. },
  73. showPsd: false,
  74. customStyle: {
  75. backgroundColor: '#fff'
  76. },
  77. dataForm: {
  78. data: ''
  79. },
  80. formConf: {},
  81. newDate: +new Date(),
  82. btnLoading: false,
  83. loading: true,
  84. modelId: '',
  85. config: {},
  86. type: 'form',
  87. listConfig: {},
  88. shortLinkData: {},
  89. formData: {},
  90. encryption: ''
  91. }
  92. },
  93. onLoad(e) {
  94. this.formData = e.formData ? JSON.parse(e.formData) : {};
  95. const decryptedData = this.jnpf.aesEncryption.decrypt(e.encryption)
  96. if (!decryptedData) return
  97. const decrypt = JSON.parse(decryptedData)
  98. this.encryption = e.encryption
  99. this.modelId = decrypt.modelId
  100. this.type = decrypt.type
  101. this.getShortLink()
  102. this.getConfig()
  103. },
  104. methods: {
  105. // 递归过滤
  106. recursivefilter(arr, value) {
  107. let newColumn = arr.filter(item => getFormDataFields(item))
  108. newColumn.forEach(x =>
  109. x.__config__ && x.__config__.children && Array.isArray(x.__config__.children) && (x
  110. .__config__.children = this.recursivefilter(x.__config__.children))
  111. )
  112. return newColumn
  113. },
  114. getConfig() {
  115. getConfig(this.modelId, this.encryption).then(res => {
  116. this.config = res.data || {}
  117. this.formConf = JSON.parse(this.config.formData) || {}
  118. this.beforeInit(this.formConf.fields)
  119. let fields = this.recursivefilter(this.formConf.fields)
  120. this.formConf.fields = fields
  121. this.fillFormData(fields, this.formData)
  122. this.$nextTick(() => {
  123. this.flg = true
  124. this.newDate = +new Date()
  125. this.loading = false
  126. })
  127. })
  128. },
  129. beforeInit(fields) {
  130. const loop = (list) => {
  131. for (var index = 0; index < list.length; index++) {
  132. const config = list[index].__config__
  133. if (config.children && config.children.length) loop(config.children)
  134. if (config.jnpfKey == 'tableGrid') {
  135. let newList = []
  136. for (var i = 0; i < config.children.length; i++) {
  137. let element = config.children[i]
  138. for (var j = 0; j < element.__config__.children.length; j++) {
  139. let item = element.__config__.children[j]
  140. newList.push(...item.__config__.children)
  141. }
  142. }
  143. list.splice(index, 1, ...newList)
  144. }
  145. }
  146. }
  147. loop(fields)
  148. },
  149. getShortLink() {
  150. getShortLink(this.modelId, this.encryption).then(res => {
  151. this.shortLinkData = res.data || {}
  152. this.columnCondition = JSON.parse(this.shortLinkData.columnCondition)
  153. this.columnText = JSON.parse(this.shortLinkData.columnText)
  154. if (this.type == 'list' && this.shortLinkData.columnPassUse == 1) this.showPsd = true
  155. if (this.type == 'form' && this.shortLinkData.formPassUse == 1) this.showPsd = true
  156. this.newDate = +new Date()
  157. })
  158. },
  159. confirm() {
  160. let data = {
  161. id: this.modelId,
  162. password: md5Libs.md5(this.password),
  163. type: this.type == 'form' ? 0 : 1,
  164. encryption: this.encryption
  165. }
  166. checkPwd(data).then(res => {
  167. this.showPsd = false
  168. this.newDate = +new Date()
  169. }).catch(err => {
  170. this.showPsd = true
  171. this.password = ''
  172. this.newDate = +new Date()
  173. })
  174. },
  175. fillFormData(form, data) {
  176. const loop = list => {
  177. for (let i = 0; i < list.length; i++) {
  178. let item = list[i]
  179. let vModel = item.__vModel__
  180. let config = item.__config__
  181. if (vModel) {
  182. let val = data.hasOwnProperty(vModel) ? data[vModel] : config
  183. .defaultValue
  184. if (!config.custom && config.defaultCurrent) {
  185. if (config.jnpfKey === 'timePicker') {
  186. config.defaultValue = this.jnpf.toDate(new Date(), this.jnpf.handelFormat(item
  187. .format))
  188. }
  189. if (config.jnpfKey === 'datePicker') {
  190. config.defaultValue = new Date().getTime()
  191. }
  192. if (config.jnpfKey === 'organizeSelect' && (this.userInfo
  193. .organizeIdList instanceof Array && this.userInfo.organizeIdList.length > 0
  194. )) {
  195. config.defaultValue = item.multiple ? [this.userInfo.organizeIdList] :
  196. this.userInfo.organizeIdList
  197. }
  198. if (config.jnpfKey === 'depSelect' && this.userInfo.departmentId) {
  199. config.defaultValue = item.multiple ? [this.userInfo.departmentId] :
  200. this.userInfo.departmentId;
  201. }
  202. if (config.jnpfKey === 'posSelect' && (this.userInfo
  203. .positionIds instanceof Array && this.userInfo.positionIds.length > 0)) {
  204. config.defaultValue = item.multiple ? this.userInfo.positionIds.map(
  205. o => o.id) : this.userInfo.positionIds[0].id
  206. }
  207. if (config.jnpfKey === 'roleSelect' && (this.userInfo
  208. .roleIds instanceof Array && this.userInfo.roleIds.length > 0)) {
  209. config.defaultValue = item.multiple ? this.userInfo.roleIds : this.userInfo
  210. .roleIds[0];
  211. }
  212. if (config.jnpfKey === 'groupSelect' && (this.userInfo
  213. .groupIds instanceof Array && this.userInfo.groupIds.length > 0)) {
  214. config.defaultValue = item.multiple ? this.userInfo.groupIds : this
  215. .userInfo.groupIds[0];
  216. }
  217. if (config.jnpfKey === 'userSelect' && this.userInfo.userId) {
  218. config.defaultValue = item.multiple ? [this.userInfo.userId] : this
  219. .userInfo.userId;
  220. }
  221. if (config.jnpfKey === 'usersSelect' && this.userInfo.userId) {
  222. config.defaultValue = item.multiple ? [this.userInfo.userId + '--user'] :
  223. this.userInfo.userId + '--user';
  224. }
  225. }
  226. if (this.origin === 'scan') {
  227. this.$set(item, 'disabled', true)
  228. }
  229. let noShow = !config.noShow ? false : config.noShow
  230. let isVisibility = false
  231. if (!config.visibility || (Array.isArray(config.visibility) && config.visibility.includes(
  232. 'app'))) isVisibility = true
  233. this.$set(config, 'isVisibility', isVisibility)
  234. this.$set(config, 'noShow', noShow)
  235. } else {
  236. let noShow = false,
  237. isVisibility = false
  238. if (!config.visibility || (Array.isArray(config.visibility) && item
  239. .__config__.visibility.includes('app'))) isVisibility = true
  240. this.$set(config, 'isVisibility', isVisibility)
  241. this.$set(config, 'noShow', noShow)
  242. }
  243. if (config && config.children && Array.isArray(config.children)) {
  244. loop(config.children)
  245. }
  246. }
  247. }
  248. loop(form)
  249. },
  250. sumbitForm(data, callback) {
  251. if (!data) return
  252. this.btnLoading = true
  253. this.dataForm.data = JSON.stringify(data)
  254. if (callback && typeof callback === "function") callback()
  255. createModel(this.modelId, this.dataForm, this.encryption).then(res => {
  256. uni.showToast({
  257. title: res.msg,
  258. complete: () => {
  259. setTimeout(() => {
  260. this.btnLoading = false
  261. this.resetForm()
  262. }, 1500)
  263. }
  264. })
  265. }).catch(() => {
  266. this.btnLoading = false
  267. })
  268. },
  269. submit() {
  270. if (this.isPreview) return this.$u.toast('功能预览不支持数据保存')
  271. this.$refs.dynamicForm && this.$refs.dynamicForm.submitForm()
  272. },
  273. resetForm() {
  274. this.loading = true
  275. this.newDate = +new Date()
  276. this.$nextTick(() => {
  277. this.loading = false
  278. this.$refs.dynamicForm && this.$refs.dynamicForm.resetForm()
  279. })
  280. }
  281. }
  282. }
  283. </script>
  284. <style lang="scss">
  285. page {
  286. background-color: #f0f2f6;
  287. }
  288. .nav {
  289. z-index: 99999;
  290. .uni-navbar__content {
  291. z-index: 99999;
  292. }
  293. .uni-navbar__header-container {
  294. justify-content: center;
  295. }
  296. }
  297. .nav-left {
  298. display: flex;
  299. align-items: center;
  300. width: 100%;
  301. text-align: center;
  302. .nav-left-text {
  303. font-weight: 700;
  304. font-size: 32rpx;
  305. flex: 1;
  306. min-width: 0;
  307. white-space: nowrap;
  308. overflow: hidden;
  309. text-overflow: ellipsis;
  310. }
  311. .right-icons {
  312. font-weight: 700;
  313. margin-top: 2px;
  314. margin-left: 4px;
  315. transition-duration: 0.3s;
  316. }
  317. .select-right-icons {
  318. transform: rotate(-180deg);
  319. }
  320. }
  321. .pasd_box {
  322. width: 100%;
  323. padding: 60% 0;
  324. display: flex;
  325. flex-direction: row;
  326. justify-content: center;
  327. align-items: center;
  328. box-sizing: border-box;
  329. .pasd_box_input {
  330. box-sizing: border-box;
  331. .ipt {
  332. border-radius: 8rpx 0 0 8rpx;
  333. border: 1px solid red;
  334. }
  335. }
  336. }
  337. </style>