分析 保存
当前位置:   article > 正文

luckysheet实例_luckysheet案例

luckysheet案例
  1. <template>
  2. <div id="app">
  3. <div class="header">
  4. <el-button type="primary" @click="startCalcHandler()">分析</el-button>
  5. <el-button round type="primary" @click="save()">保存</el-button>
  6. <el-button v-show="false" circle @click="drawer = true">
  7. <svg-icon icon-class="list" />
  8. </el-button>
  9. <el-drawer title="附加信息" :visible.sync="drawer">
  10. <el-table
  11. :data="headerConfig"
  12. border
  13. style="width: 95%; margin-left: 20px"
  14. >
  15. <!-- 第一列 -->
  16. <el-table-column property="infName" label="附加信息名称">
  17. <template slot-scope="scope">
  18. <!-- oninput="value=value.replace(/[^\d]/g,'')" -->
  19. <el-input
  20. v-if="scope.row.flag"
  21. v-model="scope.row.infName"
  22. size="mini"
  23. placeholder="请输入"
  24. />
  25. <a v-else>{{ scope.row.infName }}</a>
  26. </template>
  27. </el-table-column>
  28. <!-- 第二列 -->
  29. <el-table-column property="types" label="类型">
  30. <template slot-scope="scope">
  31. <el-select
  32. v-if="scope.row.flag"
  33. v-model="scope.row.types"
  34. clearable
  35. placeholder="请选择"
  36. size="mini"
  37. >
  38. <el-option
  39. v-for="item in options111"
  40. :key="item.value"
  41. :value="item.label"
  42. :label="item.label"
  43. />
  44. </el-select>
  45. <a v-else>{{ scope.row.types }}</a>
  46. </template>
  47. </el-table-column>
  48. <!-- 第三列 -->
  49. <el-table-column property="content" label="枚举内容(以逗号分隔)">
  50. <template slot-scope="scope">
  51. <el-input
  52. v-if="scope.row.flag"
  53. v-model="scope.row.content"
  54. size="mini"
  55. placeholder="请输入"
  56. />
  57. <a v-else>{{ scope.row.content }}</a>
  58. </template>
  59. </el-table-column>
  60. <!-- 第四列 -->
  61. <el-table-column property="edit" label="操作">
  62. <template v-slot="{ row }">
  63. <el-button
  64. v-if="row.flag === true"
  65. type="text"
  66. size="small"
  67. class="editBtn"
  68. @click="saveHandle(row)"
  69. >
  70. 保存
  71. </el-button>
  72. <el-button
  73. v-if="row.flag === false"
  74. type="text"
  75. size="small"
  76. class="editBtn"
  77. @click="editHandle(row)"
  78. >
  79. 编辑
  80. </el-button>
  81. <el-popconfirm title="确认删除?" @onConfirm="delHandle(row)">
  82. <el-button type="text" size="small">删除</el-button>
  83. </el-popconfirm>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. <el-button
  88. icon="el-icon-plus"
  89. style="width: 95%; margin: 20px"
  90. @click="addDrawerRow"
  91. >增加附加信息
  92. </el-button>
  93. <span class="drawer-footer">
  94. <el-button @click="drawer = false">取 消</el-button>
  95. <el-button type="primary" @click="drawer = false">确 定</el-button>
  96. </span>
  97. </el-drawer>
  98. </div>
  99. <div
  100. id="inputsheet"
  101. style="
  102. margin: 0px;
  103. padding: 10px;
  104. position: relative;
  105. width: 100%;
  106. height: 100%;
  107. "
  108. />
  109. </div>
  110. </template>
  111. <script>
  112. import api from '@/api/dataInput'
  113. export default {
  114. data() {
  115. return {
  116. studyType: 5,
  117. column: 0,
  118. drawer: false,
  119. // 抽屉了表格的类型的 数据对象
  120. options111: [
  121. {
  122. value: '选项1',
  123. label: '文本'
  124. },
  125. {
  126. value: '选项2',
  127. label: '数值型'
  128. },
  129. {
  130. value: '选项3',
  131. label: '下拉选择型'
  132. }
  133. ],
  134. // 控制input/select框与 普通文本谁显示
  135. // flag: false,
  136. // 抽屉里表格的 数据对象
  137. headerConfig: [
  138. {
  139. id: 0,
  140. order: 1,
  141. flag: false,
  142. infName: '行号',
  143. types: '下拉选择型',
  144. content: '1,2,3',
  145. edit: 'edit'
  146. },
  147. {
  148. id: 1,
  149. order: 2,
  150. flag: false,
  151. infName: '值',
  152. types: '文本',
  153. content: '',
  154. edit: 'edit'
  155. },
  156. {
  157. id: 2,
  158. order: 3,
  159. flag: false,
  160. infName: '日期',
  161. types: '文本',
  162. content: '',
  163. edit: 'edit'
  164. },
  165. {
  166. id: 3,
  167. order: 4,
  168. flag: false,
  169. infName: '时间',
  170. types: '文本',
  171. content: '',
  172. edit: 'edit'
  173. },
  174. {
  175. id: 4,
  176. order: 5,
  177. flag: false,
  178. infName: '机器编号',
  179. ct: {
  180. fa: 'General',
  181. t: 'g'
  182. },
  183. content: '',
  184. edit: 'edit'
  185. },
  186. {
  187. id: 5,
  188. order: 6,
  189. flag: false,
  190. infName: '模穴编号',
  191. types: '文本',
  192. content: '',
  193. edit: 'edit'
  194. },
  195. {
  196. id: 6,
  197. order: 7,
  198. flag: false,
  199. infName: '阶段',
  200. types: '文本',
  201. content: '',
  202. edit: 'edit'
  203. },
  204. {
  205. id: 7,
  206. order: 8,
  207. flag: false,
  208. infName: '检具编号',
  209. types: '文本',
  210. content: '',
  211. edit: 'edit'
  212. },
  213. {
  214. id: 8,
  215. order: 9,
  216. flag: false,
  217. infName: '检验员',
  218. types: '文本',
  219. content: '',
  220. edit: 'edit'
  221. },
  222. {
  223. id: 9,
  224. order: 10,
  225. flag: false,
  226. infName: '零件编号',
  227. types: '文本',
  228. content: '',
  229. edit: 'edit'
  230. },
  231. {
  232. id: 10,
  233. order: 11,
  234. flag: false,
  235. infName: '订单编号',
  236. types: '文本',
  237. content: '',
  238. edit: 'edit'
  239. },
  240. {
  241. id: 11,
  242. order: 12,
  243. flag: false,
  244. infName: '材料批次编号',
  245. types: '文本',
  246. content: '',
  247. edit: 'edit'
  248. },
  249. {
  250. id: 12,
  251. order: 13,
  252. flag: false,
  253. infName: '事件',
  254. types: '文本',
  255. content: '',
  256. edit: 'edit'
  257. },
  258. {
  259. id: 13,
  260. order: 14,
  261. flag: false,
  262. infName: '过程参数',
  263. types: '文本',
  264. content: '',
  265. edit: 'edit'
  266. },
  267. {
  268. id: 14,
  269. order: 15,
  270. flag: false,
  271. infName: 'id',
  272. types: '文本',
  273. content: '',
  274. edit: 'edit'
  275. }
  276. ],
  277. // 抽屉的状态
  278. table: false,
  279. options: {
  280. container: 'inputsheet', // luckysheet为容器id
  281. title: '附加信息', // 设定表格名称
  282. lang: 'zh', // 设定表格语言
  283. showtoolbar: false, // 隐藏工具栏
  284. showinfobar: false, // 隐藏顶部信息栏
  285. sheetFormulaBar: false, // 是否显示公示栏
  286. defaultFontSize: 10, // 默认字体大小
  287. showsheetbar: false,
  288. data: [
  289. {
  290. name: 'sheet1', // 工作表名称
  291. color: 'red', // 工作表名称颜色
  292. index: 9, // 工作表索引
  293. status: 1, // 激活状态
  294. order: 0, // 工作表的下标
  295. hide: 1, // 是否隐藏
  296. column: 0, // 列数
  297. defaultRowHeight: 39, // 自定义行高
  298. defaultColWidth: 140, // 自定义列宽
  299. allowEdit: true, // 是否允许前端编辑
  300. celldata: [
  301. // 初始化使用的单元格数据
  302. ],
  303. config: {
  304. merge: {}, // 合并单元格(没有反应)
  305. columnlen: {}, // 表格列宽
  306. rowhidden: {}, // 隐藏行
  307. colhidden: {
  308. 14: 0,
  309. 0: 0
  310. }, // 隐藏列
  311. authority: {
  312. // 当前工作表的权限配置
  313. sheet: 1, // 如果为1或true,则该工作表受到保护;如果为0或false,则该工作表不受保护。
  314. hintText: '这部分不可以进行修改', // 弹窗提示的文字
  315. allowRangeList: [
  316. {
  317. // 区域保护
  318. sqref: '$A$2:$N$1000' // 区域范围
  319. }
  320. ]
  321. }
  322. },
  323. scrollLeft: 0, // 左右滚动条位置
  324. scrollTop: 0, // 上下滚动条位置
  325. dataVerification: {
  326. '3_2': {
  327. type: 'dropdown',
  328. type2: null,
  329. value1: '1,2,3',
  330. value2: '',
  331. checked: false,
  332. remote: false,
  333. prohibitInput: false,
  334. hintShow: false,
  335. hintText: ''
  336. }
  337. } // 数据验证
  338. }
  339. ]
  340. },
  341. col: 0,
  342. input: '',
  343. items: [
  344. {
  345. value: '选项1',
  346. label: '文本'
  347. },
  348. {
  349. value: '选项2',
  350. label: '数值型'
  351. },
  352. {
  353. value: '选项3',
  354. label: '下拉框型'
  355. }
  356. ],
  357. value: '',
  358. data: '',
  359. list: [],
  360. cellrow: 0,
  361. // loading
  362. fullscreenLoading: false
  363. }
  364. },
  365. computed: {
  366. orgId() {
  367. return this.$store.getters.user.organizationId
  368. },
  369. projectId() {
  370. return this.$store.getters.user.currentProjectId
  371. },
  372. variableId() {
  373. return this.$store.state.plan.thirdMenuItem.id
  374. }
  375. },
  376. watch: {
  377. variableId: function () {
  378. this.init()
  379. this.getList()
  380. }
  381. },
  382. created() {
  383. this.init()
  384. this.getList()
  385. },
  386. mounted() {
  387. // 创建工作表
  388. window.luckysheet.create(this.options)
  389. this.data_ver()
  390. },
  391. methods: {
  392. data_ver() {
  393. window.luckysheet.setDataVerification(
  394. {
  395. type: 'number_integer',
  396. type2: 'gte',
  397. value1: '1',
  398. value2: '',
  399. checked: false,
  400. remote: false,
  401. prohibitInput: true,
  402. hintShow: true,
  403. hintText: '请输入整数哦'
  404. },
  405. {
  406. range: { row: [1, 100], column: [0, 0] }
  407. }
  408. )
  409. window.luckysheet.setDataVerification(
  410. {
  411. type: 'number_decimal',
  412. type2: 'gte',
  413. value1: '0.0',
  414. value2: '',
  415. checked: false,
  416. remote: false,
  417. prohibitInput: true,
  418. hintShow: true,
  419. hintText: '请输入小数哦'
  420. },
  421. {
  422. range: { row: [1, 1000], column: [1, 1] }
  423. }
  424. )
  425. window.luckysheet.setDataVerification(
  426. {
  427. type: 'date',
  428. type2: 'bw',
  429. value1: '2020-09-23',
  430. value2: '2020-10-10',
  431. checked: false,
  432. remote: false,
  433. prohibitInput: false,
  434. hintShow: false,
  435. hintText: ''
  436. },
  437. {
  438. range: { row: [1, 1000], column: [2, 3] }
  439. }
  440. )
  441. window.luckysheet.setDataVerification(
  442. {
  443. type: 'text_content',
  444. type2: 'include',
  445. value1: 'Luckysheet',
  446. value2: '',
  447. checked: false,
  448. remote: false,
  449. prohibitInput: false,
  450. hintShow: true,
  451. hintText: '请输入文本'
  452. },
  453. {
  454. range: { row: [1, 1000], column: [6, 9, 10, 11, 12, 13] }
  455. }
  456. )
  457. window.luckysheet.setDataVerification(
  458. {
  459. type: 'dropdown',
  460. type2: null,
  461. value1: '高,中,低',
  462. prohibitInput: true
  463. },
  464. {
  465. range: { row: [1, 1000], column: [4, 5, 7, 8] }
  466. }
  467. )
  468. },
  469. startCalcHandler() {
  470. api
  471. .calc({
  472. variableId: this.variableId,
  473. studyType: 2
  474. })
  475. .then((resp) => {
  476. if (resp.code !== 200) {
  477. this.$message.error('计算失败')
  478. return
  479. }
  480. this.$confirm('计算成功,是否查看分析结果?', '提示', {
  481. confirmButtonText: '确定',
  482. cancelButtonText: '取消',
  483. type: 'warning'
  484. }).then(() => {
  485. this.$store.commit('plan/isJump_OBJ', 1)
  486. this.$router.push({
  487. path: `/processAnalysis/index/${this.variableId}/${this.studyType}`
  488. })
  489. })
  490. })
  491. },
  492. init() {
  493. // 表头数据
  494. this.headerConfig.forEach((x) => {
  495. this.options.data[0].celldata.push({
  496. r: 0,
  497. c: x.order - 1,
  498. v: {
  499. ct: { fa: 'General', t: 'g' },
  500. m: 'value1',
  501. v: x.infName
  502. }
  503. })
  504. this.column++
  505. })
  506. },
  507. changeCol(row) {
  508. window.luckysheet.setCellValue(0, row.order - 1, row.infName)
  509. this.setColType(row)
  510. },
  511. addCol(row) {
  512. // 新增一列
  513. window.luckysheet.insertColumn(row.order - 1, { number: 1 })
  514. this.column++
  515. // 加上表头
  516. window.luckysheet.setCellValue(0, row.order - 1, row.infName)
  517. this.setColType(row)
  518. },
  519. setColType(row) {
  520. if (row.types === '下拉选择型') {
  521. window.luckysheet.setDataVerification(
  522. {
  523. type: 'dropdown',
  524. type2: null,
  525. value1: row.content,
  526. value2: '',
  527. checked: false,
  528. remote: false,
  529. prohibitInput: false,
  530. hintShow: false,
  531. hintText: ''
  532. },
  533. {
  534. column: [0, 1]
  535. }
  536. )
  537. } else if (row.types === '数值型') {
  538. window.luckysheet.setDataVerification({
  539. type: 'number',
  540. type2: 'gte',
  541. value1: '1',
  542. value2: '',
  543. checked: false,
  544. remote: false,
  545. prohibitInput: true,
  546. hintShow: false,
  547. hintText: ''
  548. })
  549. } else {
  550. window.luckysheet.setDataVerification({
  551. type: 'text_content',
  552. type2: 'include',
  553. value1: 'Luckysheet',
  554. value2: '',
  555. checked: false,
  556. remote: false,
  557. prohibitInput: false,
  558. hintShow: true,
  559. hintText: 'include Luckysheet'
  560. })
  561. }
  562. },
  563. resetOrder(order) {
  564. this.headerConfig
  565. .filter((x) => x.order > order)
  566. .forEach((x) => {
  567. x.order--
  568. })
  569. // TODO 同步grid信息到数据库
  570. },
  571. delRow(row) {
  572. const index = row.order - 1
  573. this.headerConfig.splice(index, 1)
  574. window.luckysheet.deleteColumn(index, index)
  575. window.luckysheet.hideColumn(this.column - 1, 999)
  576. this.column--
  577. this.resetOrder(row.order)
  578. },
  579. addDrawerRow() {
  580. const tempRow = {
  581. order: this.headerConfig.length + 1,
  582. flag: true,
  583. infName: '',
  584. types: '',
  585. content: '',
  586. edit: 'save'
  587. }
  588. this.headerConfig.push(tempRow)
  589. },
  590. editHandle(row) {
  591. const index = row.order - 1
  592. this.headerConfig[index].flag = !this.headerConfig[index].flag
  593. this.headerConfig[index].edit = 'save'
  594. },
  595. saveHandle(row) {
  596. const index = row.order - 1
  597. this.headerConfig[index].flag = !this.headerConfig[index].flag
  598. this.headerConfig[index].edit = 'edit'
  599. // TODO 更新数据库中的列信息
  600. this.submitRowData(row)
  601. },
  602. submitRowData(row) {
  603. const index = row.order - 1
  604. if (this.column < row.order) {
  605. this.addCol(row)
  606. } else {
  607. this.changeCol(row)
  608. }
  609. this.headerConfig[index].infName = row.infName
  610. this.headerConfig[index].types = row.types
  611. this.headerConfig[index].content = row.content
  612. },
  613. delHandle(row) {
  614. // TODO 删除数据库中的列信息
  615. this.delRow(row)
  616. },
  617. // 获取初始过程研究数据
  618. async getList() {
  619. if (this.variableId === null || this.variableId === '') {
  620. return
  621. }
  622. const { code, data } = await api.showData(this.variableId)
  623. if (code !== 200) {
  624. this.$message.error('获取数据失败!')
  625. return
  626. }
  627. this.list = data
  628. window.luckysheet.destroy()
  629. var i = 1
  630. this.list.forEach((x) => {
  631. const data = x
  632. this.options.data[0].data[i] = new Array(15)
  633. this.options.data[0].data[i] = []
  634. this.options.data[0].data[i][0] = {
  635. v: data.idx
  636. }
  637. this.options.data[0].data[i][1] = {
  638. v: data.value
  639. }
  640. this.options.data[0].data[i][2] = {
  641. v: data.inputDate
  642. }
  643. this.options.data[0].data[i][3] = {
  644. v: data.inputTime
  645. }
  646. this.options.data[0].data[i][4] = {
  647. v: data.machineNumber
  648. }
  649. this.options.data[0].data[i][5] = {
  650. v: data.cavityNumber
  651. }
  652. this.options.data[0].data[i][6] = {
  653. v: data.stage
  654. }
  655. this.options.data[0].data[i][7] = {
  656. v: data.gaugeNumber
  657. }
  658. this.options.data[0].data[i][8] = {
  659. v: data.inspector
  660. }
  661. this.options.data[0].data[i][9] = {
  662. v: data.componentNumber
  663. }
  664. this.options.data[0].data[i][10] = {
  665. v: data.orderNumber
  666. }
  667. this.options.data[0].data[i][11] = {
  668. v: data.batchNumber
  669. }
  670. this.options.data[0].data[i][12] = {
  671. v: data.event
  672. }
  673. this.options.data[0].data[i][13] = {
  674. v: data.processParameter
  675. }
  676. this.options.data[0].data[i][14] = {
  677. v: data.id
  678. }
  679. i++
  680. })
  681. if (this.list.length < 84) {
  682. this.options.data[0].data.splice(84)
  683. } else if (this.options.data[0].data.length - this.list.length > 3) {
  684. this.options.data[0].data.splice(this.list.length + 1)
  685. }
  686. for (var j = i; j < this.options.data[0].data.length; j++) {
  687. this.options.data[0].data[j] = []
  688. }
  689. window.luckysheet.create(this.options)
  690. },
  691. // 数据保存
  692. async save() {
  693. const loading = this.$loading({
  694. lock: true,
  695. text: '保存中',
  696. spinner: 'el-icon-loading',
  697. background: 'rgba(0, 0, 0, 0.7)'
  698. })
  699. var celldata = window.luckysheet.transToCellData(
  700. window.luckysheet.getLuckysheetfile()[0].data
  701. )
  702. let count = 1
  703. let idxIncrease = 1
  704. const list = []
  705. while (count <= celldata[celldata.length - 1].r) {
  706. const data = {}
  707. const res = celldata.filter((x) => x.r === count)
  708. if (res) {
  709. data['idx'] = idxIncrease
  710. res.forEach((x) => {
  711. switch (x.c) {
  712. case 1:
  713. data['value'] = x.v.v
  714. return
  715. case 2:
  716. data['inputDate'] = x.v.v
  717. return
  718. case 3:
  719. data['inputTime'] = x.v.v
  720. return
  721. case 4:
  722. data['machineNumber'] = x.v.v
  723. return
  724. case 5:
  725. data['cavityNumber'] = x.v.v
  726. return
  727. case 6:
  728. data['stage'] = x.v.v
  729. return
  730. case 7:
  731. data['gaugeNumber'] = x.v.v
  732. return
  733. case 8:
  734. data['inspector'] = x.v.v
  735. return
  736. case 9:
  737. data['componentNumber'] = x.v.v
  738. return
  739. case 10:
  740. data['orderNumber'] = x.v.v
  741. return
  742. case 11:
  743. data['batchNumber'] = x.v.v
  744. return
  745. case 12:
  746. data['event'] = x.v.v
  747. return
  748. case 13:
  749. data['processParameter'] = x.v.v
  750. return
  751. case 14:
  752. if (x.v.v && x.v.v !== '' && x.v.v !== null) {
  753. data.id = x.v.v
  754. }
  755. return
  756. default:
  757. return
  758. }
  759. })
  760. list.push(data)
  761. } else {
  762. continue
  763. }
  764. count++
  765. idxIncrease++
  766. }
  767. const subList = []
  768. list.forEach((item, index) => {
  769. subList.push({
  770. idx: item.idx,
  771. value: item.value,
  772. inputDate: item.inputDate,
  773. inputTime: item.inputTime,
  774. machineNumber: item.machineNumber,
  775. cavityNumber: item.cavityNumber,
  776. stage: item.stage,
  777. gaugeNumber: item.gaugeNumber,
  778. inspector: item.inspector,
  779. componentNumber: item.componentNumber,
  780. orderNumber: item.orderNumber,
  781. batchNumber: item.batchNumber,
  782. event: item.event,
  783. processParameter: item.processParameter
  784. })
  785. })
  786. let flag = 0
  787. subList.forEach((x) => {
  788. if (x.value === undefined) {
  789. flag = 1
  790. }
  791. })
  792. if (flag === 1) {
  793. this.$message.info('值为必填项,请检查表格数据')
  794. loading.close()
  795. return
  796. }
  797. const addResp = await api.new_add(
  798. this.projectId,
  799. this.variableId,
  800. subList
  801. )
  802. if (addResp.code !== 200) {
  803. this.$message.error('保存失败')
  804. loading.close()
  805. return
  806. }
  807. this.$message.success('保存成功')
  808. this.getList()
  809. loading.close()
  810. }
  811. }
  812. }
  813. </script>
  814. <style scoped>
  815. .header {
  816. display: flex;
  817. justify-content: flex-end;
  818. }
  819. ::v-deep .btn123 {
  820. border-radius: 10px;
  821. border-style: dashed;
  822. width: 100%;
  823. margin-top: 15px;
  824. }
  825. .drawer-footer {
  826. width: 100%;
  827. position: absolute;
  828. bottom: 0;
  829. left: 0;
  830. border-top: 1px solid #e8e8e8;
  831. padding: 10px 16px;
  832. text-align: right;
  833. background-color: white;
  834. }
  835. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/396087
推荐阅读
相关标签