index.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <template>
  2. <div class="form-designer">
  3. <el-container>
  4. <!-- 左侧字段 -->
  5. <el-aside :width="leftWidth">
  6. <div class="fields-list">
  7. <template v-if="customFields && customFields.length > 0">
  8. <template v-if="customFields[0].title && customFields[0].list && customFields[0].list.length > 0">
  9. <template v-for="(field, index) in customFields">
  10. <div class="field-title" :key="'f_' + index">{{ field.title }}</div>
  11. <draggable
  12. tag="ul"
  13. :list="field.list"
  14. :group="{ name: 'form', pull: 'clone', put: false }"
  15. ghost-class="ghost"
  16. :sort="false"
  17. :key="'d_' + index"
  18. >
  19. <template v-for="(item, cIndex) in field.list">
  20. <li class="field-label" :key="'c_' + cIndex">
  21. <a @click="handleFieldClick(item)">
  22. <i class="icon iconfont" :class="item.icon"></i>
  23. <span>{{ item.title || item.label }}</span>
  24. </a>
  25. </li>
  26. </template>
  27. </draggable>
  28. </template>
  29. </template>
  30. <template v-else>
  31. <draggable tag="ul" :list="customFields" :group="{ name: 'form', pull: 'clone', put: false }" ghost-class="ghost" :sort="false">
  32. <template v-for="(item, index) in customFields">
  33. <el-tooltip v-if="item.tips" effect="dark" :content="item.tips" :key="index">
  34. <li class="field-label" :key="index">
  35. <a style="padding: 0 5px" @click="handleFieldClick(item)">
  36. <i :class="item.icon"></i>
  37. <span style="margin-left: 5px">{{ item.title || item.label }}</span>
  38. </a>
  39. </li>
  40. </el-tooltip>
  41. <li v-else class="field-label" :key="index">
  42. <a style="padding: 0 5px" @click="handleFieldClick(item)">
  43. <i :class="item.icon"></i>
  44. <span style="margin-left: 5px">{{ item.title || item.label }}</span>
  45. </a>
  46. </li>
  47. </template>
  48. </draggable>
  49. </template>
  50. </template>
  51. <div v-for="(field, index) in fields" :key="index">
  52. <template v-if="field.list.find((f) => includeFields.includes(f.type))">
  53. <div class="field-title">{{ field.title }}</div>
  54. <draggable tag="ul" :list="field.list" :group="{ name: 'form', pull: 'clone', put: false }" ghost-class="ghost" :sort="false">
  55. <template v-for="(item, cIndex) in field.list">
  56. <li class="field-label" v-if="includeFields.includes(item.type)" :key="'c_' + cIndex">
  57. <a @click="handleFieldClick(item)">
  58. <i class="icon iconfont" :class="item.icon"></i>
  59. <span>{{ item.title || item.label }}</span>
  60. </a>
  61. </li>
  62. </template>
  63. </draggable>
  64. </template>
  65. </div>
  66. </div>
  67. </el-aside>
  68. <!-- 中间主布局 -->
  69. <el-container class="widget-container" direction="vertical">
  70. <el-header class="widget-container-header">
  71. <div>
  72. <template v-if="undoRedo">
  73. <el-button type="text" size="medium" icon="el-icon-refresh-left" :disabled="historySteps.index == 0" @click="widgetForm = handleUndo()"
  74. >撤销</el-button
  75. >
  76. <el-button
  77. type="text"
  78. size="medium"
  79. icon="el-icon-refresh-right"
  80. :disabled="historySteps.index == historySteps.steps.length - 1"
  81. @click="widgetForm = handleRedo()"
  82. >重做</el-button
  83. >
  84. </template>
  85. </div>
  86. <div style="display: flex; align-items: center">
  87. <el-button v-if="toolbar.includes('generate')" type="text" size="medium" icon="el-icon-download" @click="handleGenerateJson">生成JSON</el-button>
  88. <el-button v-if="toolbar.includes('preview')" type="text" size="medium" icon="el-icon-view" @click="handlePreview">预览</el-button>
  89. <el-button v-if="toolbar.includes('clear')" class="danger" type="text" size="medium" icon="el-icon-delete" @click="handleClear">清空</el-button>
  90. <slot name="toolbar"></slot>
  91. </div>
  92. </el-header>
  93. <el-main :style="{ background: widgetForm.column.length == 0 ? `url(${widgetEmpty}) no-repeat 50%` : '' }">
  94. <widget-form ref="widgetForm" :data="widgetForm" :select.sync="widgetFormSelect" @change="handleHistoryChange(widgetForm)"></widget-form>
  95. </el-main>
  96. </el-container>
  97. <!-- 右侧配置 -->
  98. <el-aside class="widget-config-container" :width="rightWidth">
  99. <el-tabs v-model="configTab" stretch>
  100. <el-tab-pane label="字段属性" name="widget" style="padding: 0 10px">
  101. <widget-config :data="widgetFormSelect" :default-values="defaultValues"></widget-config>
  102. </el-tab-pane>
  103. <el-tab-pane label="表单属性" name="form" lazy style="padding: 0 10px">
  104. <form-config :data="widgetForm"></form-config>
  105. </el-tab-pane>
  106. </el-tabs>
  107. </el-aside>
  108. <!-- 生成JSON -->
  109. <el-drawer title="生成JSON" :visible.sync="generateJsonVisible" size="50%" append-to-body destroy-on-close>
  110. <monaco-editor v-model="option" keyIndex="generate" height="82%" :read-only="true"></monaco-editor>
  111. <div class="afd-drawer-foot">
  112. <el-button size="medium" type="primary" @click="handleGenerate">生成</el-button>
  113. <el-popover placement="top" trigger="hover" width="350px">
  114. <el-form v-model="configOption" style="padding: 0 20px" label-suffix=":" label-width="180px" label-position="left">
  115. <el-form-item label="类型">
  116. <el-popover placement="top-start" trigger="hover" content="复制json对象" style="margin-right: 15px">
  117. <el-radio slot="reference" v-model="configOption.generateType" label="json">json</el-radio>
  118. </el-popover>
  119. <el-popover placement="top-start" trigger="hover" content="复制string字符串,可直接用于后端保存无需再次处理。">
  120. <el-radio slot="reference" v-model="configOption.generateType" label="string">string</el-radio>
  121. </el-popover>
  122. </el-form-item>
  123. <el-form-item label="缩进长度-空格数量">
  124. <el-slider v-model="configOption.space" show-stops :marks="{ 1: '1', 2: '2', 3: '3', 4: '4' }" :min="1" :max="4" :step="1"></el-slider>
  125. </el-form-item>
  126. <el-form-item label="引号类型">
  127. <el-switch
  128. v-model="configOption.quoteType"
  129. active-value="single"
  130. inactive-value="double"
  131. active-text="单引号"
  132. inactive-text="双引号"
  133. ></el-switch>
  134. </el-form-item>
  135. <el-form-item label="移除key的引号">
  136. <el-switch v-model="configOption.dropQuotesOnKeys"></el-switch>
  137. </el-form-item>
  138. <el-form-item label="移除数字字符串的引号">
  139. <el-switch v-model="configOption.dropQuotesOnNumbers"></el-switch>
  140. </el-form-item>
  141. </el-form>
  142. <el-button size="medium" type="primary" @click="handleCopy" slot="reference" style="margin-left: 10px">复制</el-button>
  143. </el-popover>
  144. </div>
  145. </el-drawer>
  146. <!-- 预览 -->
  147. <el-drawer title="预览" :visible.sync="previewVisible" size="60%" append-to-body :before-close="handleBeforeClose">
  148. <avue-form ref="form" class="afd-preview-form" :option="option" v-model="form" @submit="handlePreviewSubmit"></avue-form>
  149. <div class="afd-drawer-foot">
  150. <el-button size="medium" type="primary" @click="handlePreviewSubmit">确定</el-button>
  151. <el-button size="medium" type="danger" @click="handleBeforeClose">取消</el-button>
  152. </div>
  153. </el-drawer>
  154. </el-container>
  155. </div>
  156. </template>
  157. <script>
  158. import fields from './fieldsConfig.js'
  159. import beautifier from './utils/json-beautifier'
  160. import MonacoEditor from './utils/monaco-editor'
  161. import widgetEmpty from './assets/widget-empty.png'
  162. import history from './mixins/history'
  163. import Draggable from 'vuedraggable'
  164. import WidgetForm from './WidgetForm'
  165. import FormConfig from './FormConfig'
  166. import WidgetConfig from './WidgetConfig'
  167. export default {
  168. name: 'FormDesign',
  169. components: { Draggable, MonacoEditor, WidgetForm, FormConfig, WidgetConfig },
  170. mixins: [history],
  171. props: {
  172. options: {
  173. type: [Object, String],
  174. default: () => {
  175. return {
  176. column: [],
  177. }
  178. },
  179. },
  180. storage: {
  181. type: Boolean,
  182. default: false,
  183. },
  184. asideLeftWidth: {
  185. type: [String, Number],
  186. default: '270px',
  187. },
  188. asideRightWidth: {
  189. type: [String, Number],
  190. default: '380px',
  191. },
  192. toolbar: {
  193. type: Array,
  194. default: () => {
  195. return ['import', 'generate', 'preview', 'clear']
  196. },
  197. },
  198. undoRedo: {
  199. type: Boolean,
  200. default: true,
  201. },
  202. includeFields: {
  203. type: Array,
  204. default: () => {
  205. const arr = []
  206. fields.forEach((f) => {
  207. f.list.forEach((c) => {
  208. arr.push(c.type)
  209. })
  210. })
  211. return arr
  212. },
  213. },
  214. customFields: {
  215. type: Array,
  216. },
  217. defaultValues: {
  218. type: Object,
  219. },
  220. },
  221. watch: {
  222. options: {
  223. handler(val) {
  224. let options = val
  225. if (typeof options == 'string') {
  226. try {
  227. options = eval('(' + options + ')')
  228. } catch (e) {
  229. console.error('非法配置')
  230. options = { column: [] }
  231. }
  232. }
  233. this.transAvueOptionsToFormDesigner(options).then((res) => {
  234. this.widgetForm = { ...this.widgetForm, ...res }
  235. })
  236. },
  237. deep: true,
  238. },
  239. widgetFormSelect: {
  240. handler() {
  241. if (this.configTab == 'form') this.configTab = 'widget'
  242. },
  243. deep: true,
  244. },
  245. },
  246. computed: {
  247. leftWidth() {
  248. if (typeof this.asideLeftWidth == 'string') {
  249. return this.asideLeftWidth
  250. } else {
  251. return `${this.asideLeftWidth}px`
  252. }
  253. },
  254. rightWidth() {
  255. if (typeof this.asideRightWidth == 'string') {
  256. return this.asideRightWidth
  257. } else {
  258. return `${this.asideRightWidth}px`
  259. }
  260. },
  261. },
  262. data() {
  263. return {
  264. widgetEmpty,
  265. fields,
  266. widgetForm: {
  267. column: [],
  268. labelPosition: 'left',
  269. labelSuffix: ':',
  270. labelWidth: 120,
  271. gutter: 0,
  272. menuBtn: true,
  273. submitBtn: true,
  274. submitText: '提交',
  275. emptyBtn: true,
  276. emptyText: '清空',
  277. menuPosition: 'center',
  278. },
  279. option: {},
  280. configTab: 'form',
  281. widgetFormSelect: {},
  282. previewVisible: false,
  283. generateJsonVisible: false,
  284. importJson: {},
  285. form: {},
  286. configOption: {
  287. generateType: 'json',
  288. space: 2,
  289. quoteType: 'single',
  290. dropQuotesOnKeys: true,
  291. },
  292. history: {
  293. index: 0, // 当前下标
  294. maxStep: 20, // 最大记录步数
  295. steps: [], // 历史步数
  296. },
  297. }
  298. },
  299. mounted() {
  300. this.handleLoadStorage()
  301. this.handleLoadCss()
  302. },
  303. methods: {
  304. // 组件初始化时加载本地存储中的options(需开启storage),若不存在则读取用户配置的options
  305. async handleLoadStorage() {
  306. let options = this.options
  307. if (typeof options == 'string') {
  308. try {
  309. options = eval('(' + options + ')')
  310. } catch (e) {
  311. console.error('非法配置')
  312. options = { column: [] }
  313. }
  314. }
  315. if (!options.column) options.column = []
  316. this.widgetForm = this.initHistory({
  317. index: 0,
  318. maxStep: 20,
  319. steps: [await this.transAvueOptionsToFormDesigner({ ...this.widgetForm, ...options })],
  320. storage: this.storage,
  321. })
  322. if (this.undoRedo) {
  323. window.addEventListener(
  324. 'keydown',
  325. (evt) => {
  326. // 监听 cmd + z / ctrl + z 撤销
  327. if ((evt.metaKey && !evt.shiftKey && evt.keyCode == 90) || (evt.ctrlKey && !evt.shiftKey && evt.keyCode == 90)) {
  328. this.widgetForm = this.handleUndo()
  329. }
  330. // 监听 cmd + shift + z / ctrl + shift + z / ctrl + y 重做
  331. if (
  332. (evt.metaKey && evt.shiftKey && evt.keyCode == 90) ||
  333. (evt.ctrlKey && evt.shiftKey && evt.keyCode == 90) ||
  334. (evt.ctrlKey && evt.keyCode == 89)
  335. ) {
  336. this.widgetForm = this.handleRedo()
  337. }
  338. },
  339. false
  340. )
  341. }
  342. },
  343. // 加载icon
  344. handleLoadCss() {
  345. const head = document.getElementsByTagName('head')[0]
  346. const script = document.createElement('link')
  347. script.rel = 'stylesheet'
  348. script.type = 'text/css'
  349. script.href = 'https://at.alicdn.com/t/font_1254447_zc9iezc230c.css'
  350. head.appendChild(script)
  351. },
  352. // 左侧字段点击
  353. handleFieldClick(item) {
  354. const activeIndex = this.widgetForm.column.findIndex((c) => c.prop == this.widgetFormSelect.prop) + 1
  355. let newIndex = 0
  356. if (activeIndex == -1) {
  357. this.widgetForm.column.push(item)
  358. newIndex = this.widgetForm.column.length - 1
  359. } else {
  360. this.widgetForm.column.splice(activeIndex, 0, item)
  361. newIndex = activeIndex
  362. }
  363. this.$refs.widgetForm.handleWidgetAdd({ newIndex })
  364. },
  365. // 预览 - 弹窗
  366. handlePreview() {
  367. if (!this.widgetForm.column || this.widgetForm.column.length == 0) this.$message.error('没有需要展示的内容')
  368. else {
  369. this.transformToAvueOptions(this.widgetForm, true).then((data) => {
  370. this.option = data
  371. this.previewVisible = true
  372. })
  373. }
  374. },
  375. // 生成JSON - 弹窗
  376. handleGenerateJson() {
  377. this.transformToAvueOptions(this.widgetForm).then((data) => {
  378. this.option = data
  379. this.generateJsonVisible = true
  380. })
  381. },
  382. // 生成JSON - 弹窗 - 确定
  383. handleGenerate() {
  384. this.transformToAvueOptions(this.widgetForm).then((data) => {
  385. if (this.configOption.generateType && this.configOption.generateType == 'string')
  386. this.$emit(
  387. 'submit',
  388. beautifier(data, {
  389. minify: true,
  390. ...this.configOption,
  391. })
  392. )
  393. else this.$emit('submit', data)
  394. })
  395. },
  396. // 生成JSON - 弹窗 - 拷贝
  397. handleCopy() {
  398. this.transformToAvueOptions(this.widgetForm).then((data) => {
  399. this.$Clipboard({
  400. text: beautifier(data, {
  401. minify: true,
  402. ...this.configOption,
  403. }),
  404. })
  405. .then(() => {
  406. this.$message.success('复制成功')
  407. })
  408. .catch(() => {
  409. this.$message.error('复制失败')
  410. })
  411. })
  412. },
  413. // 预览 - 弹窗 - 确定
  414. handlePreviewSubmit(form, done) {
  415. if (done) {
  416. this.$alert(this.form)
  417. .then(() => {
  418. done()
  419. })
  420. .catch(() => {
  421. done()
  422. })
  423. } else {
  424. this.$refs.form.validate((valid, done) => {
  425. if (valid)
  426. this.$alert(this.form)
  427. .then(() => {
  428. done()
  429. })
  430. .catch(() => {
  431. done()
  432. })
  433. })
  434. }
  435. },
  436. // 预览 - 弹窗 - 关闭前
  437. handleBeforeClose() {
  438. this.$refs.form.resetForm()
  439. this.form = {}
  440. this.previewVisible = false
  441. },
  442. // 清空
  443. handleClear() {
  444. if (this.widgetForm && this.widgetForm.column && this.widgetForm.column.length > 0) {
  445. this.$confirm('确定要清空吗?', '警告', {
  446. type: 'warning',
  447. })
  448. .then(() => {
  449. this.$set(this.widgetForm, 'column', [])
  450. this.$set(this, 'form', {})
  451. this.$set(this, 'widgetFormSelect', {})
  452. this.handleHistoryChange(this.widgetForm)
  453. })
  454. .catch(() => {})
  455. } else this.$message.error('没有需要清空的内容')
  456. },
  457. // 表单设计器配置项 转化为 Avue配置项
  458. transformToAvueOptions(obj, isPreview = false) {
  459. const _this = this
  460. return new Promise((resolve, reject) => {
  461. try {
  462. const data = _this.deepClone(obj)
  463. for (let i = 0; i < data.column.length; i++) {
  464. const col = data.column[i]
  465. if (isPreview) {
  466. // 预览调整事件中的this指向
  467. let event = ['change', 'blur', 'click', 'focus']
  468. event.forEach((e) => {
  469. if (col[e]) col[e] = eval((col[e] + '').replace(/this/g, '_this'))
  470. })
  471. if (col.event) Object.keys(col.event).forEach((key) => (col.event[key] = eval((col.event[key] + '').replace(/this/g, '_this'))))
  472. }
  473. if (col.type == 'dynamic' && col.children && col.children.column && col.children.column.length > 0) {
  474. const c = col.children.column
  475. c.forEach((item) => {
  476. delete item.subfield
  477. })
  478. this.transformToAvueOptions(col.children, isPreview).then((res) => {
  479. col.children = res
  480. })
  481. } else if (col.type == 'group') {
  482. if (!data.group) data.group = []
  483. const group = {
  484. label: col.label,
  485. icon: col.icon,
  486. prop: col.prop,
  487. arrow: col.arrow,
  488. collapse: col.collapse,
  489. display: col.display,
  490. }
  491. this.transformToAvueOptions(col.children, isPreview).then((res) => {
  492. group.column = res.column
  493. data.group.push(group)
  494. })
  495. data.column.splice(i, 1)
  496. i--
  497. } else if (['checkbox', 'radio', 'tree', 'cascader', 'select'].includes(col.type)) {
  498. if (col.dicOption == 'static') {
  499. delete col.dicUrl
  500. delete col.dicMethod
  501. delete col.dicQuery
  502. delete col.dicQueryConfig
  503. } else if (col.dicOption == 'remote') {
  504. delete col.dicData
  505. if (col.dicQueryConfig && col.dicQueryConfig.length > 0) {
  506. const query = {}
  507. col.dicQueryConfig.forEach((q) => {
  508. if (q.key && q.value) query[q.key] = q.value
  509. })
  510. col.dicQuery = query
  511. delete col.dicQueryConfig
  512. } else delete col.dicQueryConfig
  513. }
  514. delete col.dicOption
  515. } else if (['upload'].includes(col.type)) {
  516. if (col.headersConfig && col.headersConfig.length > 0) {
  517. const headers = {}
  518. col.headersConfig.forEach((h) => {
  519. if (h.key && h.value) headers[h.key] = h.value
  520. })
  521. col.headers = headers
  522. } else delete col.headers
  523. delete col.headersConfig
  524. if (col.dataConfig && col.dataConfig.length > 0) {
  525. const data = {}
  526. col.dataConfig.forEach((h) => {
  527. if (h.key && h.value) data[h.key] = h.value
  528. })
  529. col.data = data
  530. } else delete col.data
  531. delete col.dataConfig
  532. }
  533. }
  534. resolve(data)
  535. } catch (e) {
  536. reject(e)
  537. }
  538. })
  539. },
  540. // Avue配置项 转化为 表单设计器配置项
  541. transAvueOptionsToFormDesigner(obj) {
  542. if (typeof obj == 'string') obj = eval('(' + obj + ')')
  543. const data = this.deepClone(obj)
  544. return new Promise((resolve, reject) => {
  545. try {
  546. if (data.column && data.column.length > 0) {
  547. data.column.forEach((col) => {
  548. if (col.type == 'dynamic' && col.children && col.children.column && col.children.column.length > 0) {
  549. const c = col.children.column
  550. c.forEach((item) => {
  551. item.subfield = true
  552. })
  553. this.transAvueOptionsToFormDesigner(col.children).then((res) => {
  554. col.children = res
  555. })
  556. } else if (['checkbox', 'radio', 'tree', 'cascader', 'select'].includes(col.type)) {
  557. if (!col.dicData && col.dicQuery && typeof col.dicQuery == 'object') {
  558. const arr = []
  559. for (let key in col.dicQuery) {
  560. arr.push({
  561. key,
  562. value: col.dicQuery[key],
  563. $cellEdit: true,
  564. })
  565. }
  566. col.dicQueryConfig = arr
  567. }
  568. if (col.dicUrl) col.dicOption = 'remote'
  569. else col.dicOption = 'static'
  570. if (!col.dicData) col.dicData = []
  571. } else if (['upload'].includes(col.type)) {
  572. if (col.headers && typeof col.headers == 'object') {
  573. const arr = []
  574. for (let key in col.headers) {
  575. arr.push({
  576. key,
  577. value: col.headers[key],
  578. $cellEdit: true,
  579. })
  580. }
  581. col.headersConfig = arr
  582. } else col.headersConfig = []
  583. if (col.data && typeof col.data == 'object') {
  584. const arr = []
  585. for (let key in col.data) {
  586. arr.push({
  587. key,
  588. value: col.data[key],
  589. $cellEdit: true,
  590. })
  591. }
  592. col.dataConfig = arr
  593. } else col.dataConfig = []
  594. }
  595. })
  596. }
  597. if (data.group && data.group.length > 0) {
  598. for (let i = 0; i < data.group.length; i++) {
  599. if (!data.column) data.column = []
  600. const col = data.group[i]
  601. const group = {
  602. type: 'group',
  603. label: col.label,
  604. icon: col.icon,
  605. prop: col.prop,
  606. arrow: col.arrow,
  607. collapse: col.collapse,
  608. display: col.display,
  609. }
  610. this.transAvueOptionsToFormDesigner(col).then((res) => {
  611. group.children = res
  612. data.column.push(group)
  613. })
  614. }
  615. delete data.group
  616. }
  617. resolve(data)
  618. } catch (e) {
  619. reject(e)
  620. }
  621. })
  622. },
  623. async getData(type = 'json', option = {}) {
  624. if (type == 'string')
  625. return beautifier(await this.transformToAvueOptions(this.widgetForm), {
  626. minify: true,
  627. ...option,
  628. })
  629. else if (type == 'app') {
  630. const option = await this.transformToAvueOptions(this.widgetForm)
  631. this.parseJson(option)
  632. return option
  633. } else return await this.transformToAvueOptions(this.widgetForm)
  634. },
  635. parseJson(jsonObj) {
  636. // 循环所有键
  637. for (var key in jsonObj) {
  638. //如果对象类型为object类型且数组长度大于0 或者 是对象 ,继续递归解析
  639. var element = jsonObj[key]
  640. if ((element && element.length > 0 && typeof element == 'object') || typeof element == 'object') {
  641. this.parseJson(element)
  642. } else if (typeof element == 'function') {
  643. jsonObj[key] = element + ''
  644. }
  645. }
  646. },
  647. },
  648. }
  649. </script>
  650. <style lang="scss">
  651. @import './styles/index.scss';
  652. </style>