setInputTPT.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <template>
  2. <div>
  3. <div class="setInputcss">
  4. <el-row :span="24">
  5. <el-col :span="3.3" style="line-height: 40px">
  6. 元素坐标:
  7. </el-col>
  8. <el-col :span="18">
  9. <avue-input v-model="htmlData.name" placeholder="请输入内容" :disabled='true'></avue-input>
  10. </el-col>
  11. </el-row>
  12. <el-row :span="24">
  13. <el-col :span="3.3" style="line-height: 40px">
  14. 文本格式:
  15. </el-col>
  16. <el-col :span="18">
  17. <el-select style="width:100%;" v-model="from.type" clearable placeholder="请选择">
  18. <el-option v-for="item in kjtype" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey">
  19. </el-option>
  20. </el-select>
  21. </el-col>
  22. </el-row>
  23. <el-row :span="24" v-if="from.type==='date'||from.type==='daterange'">
  24. <el-col :span="3.8" style="line-height: 40px">
  25. 日期:
  26. </el-col>
  27. <el-col :span="8">
  28. <el-checkbox-group v-model="checkDateList" style="margin-top: 10px;margin-left: 10px;" size="large" @change="changeDate">
  29. <el-checkbox v-for="item in yearList" :label="item.value">{{ item.name }}</el-checkbox>
  30. </el-checkbox-group>
  31. </el-col>
  32. <el-col :span="3.8" style="line-height: 40px">
  33. 分隔符:
  34. </el-col>
  35. <el-col :span="8" style="margin-left: 10px;">
  36. <el-select
  37. style="width:100%;"
  38. v-model="from.divide_y"
  39. clearable
  40. placeholder="请选择"
  41. >
  42. <el-option
  43. label="文本"
  44. value="文本"
  45. >
  46. </el-option>
  47. <el-option
  48. label="-"
  49. value="-"
  50. >
  51. </el-option>
  52. <el-option
  53. label="/"
  54. value="/"
  55. >
  56. </el-option>
  57. </el-select>
  58. </el-col>
  59. </el-row>
  60. <el-row :span="24" v-if="from.type==='date'||from.type==='daterange'">
  61. <el-col :span="3.8" style="line-height: 40px">
  62. 时间:
  63. </el-col>
  64. <el-col :span="8">
  65. <el-checkbox-group v-model="checkTimeist" style="margin-top: 10px;margin-left: 10px;" size="large" @change="changeTime">
  66. <el-checkbox v-for="item in timeList" :label="item.value">{{ item.name }}</el-checkbox>
  67. </el-checkbox-group>
  68. </el-col>
  69. <el-col :span="3.8" style="line-height: 40px">
  70. 分隔符:
  71. </el-col>
  72. <el-col :span="8" style="margin-left: 10px;">
  73. <el-select
  74. style="width:100%;"
  75. v-model="from.divide_h"
  76. clearable
  77. placeholder="请选择"
  78. >
  79. <el-option
  80. label="文本"
  81. value="文本"
  82. >
  83. </el-option>
  84. <el-option
  85. label=":"
  86. value=":"
  87. >
  88. </el-option>
  89. <el-option
  90. label="/"
  91. value="/"
  92. >
  93. </el-option>
  94. </el-select>
  95. </el-col>
  96. </el-row>
  97. <el-row :span="24" v-if="from.type==='daterange'">
  98. <el-col :span="3.3" style="line-height: 40px">
  99. 中间分隔符:
  100. </el-col>
  101. <el-col :span="18" style="margin-left: 10px;">
  102. <el-select
  103. style="width:100%;"
  104. v-model="from.divide_c"
  105. clearable
  106. placeholder="请选择"
  107. >
  108. <el-option
  109. label="至"
  110. value='至'
  111. >
  112. </el-option>
  113. <el-option
  114. label="-"
  115. value="-"
  116. >
  117. </el-option>
  118. <el-option
  119. label="~"
  120. value="~"
  121. >
  122. </el-option>
  123. </el-select>
  124. </el-col>
  125. </el-row>
  126. </div>
  127. <!-- 添加框 -->
  128. <div style="border: 1px dotted rgb(187, 187, 187);box-sizing: border-box;padding: 0px 15px;"
  129. class="martop20 marbottom10" v-show="from.type == 'select' || from.type == 'radio' || from.type == 'checkbox'|| from.type == 'selectBox'">
  130. <table class="table" width='100%' border='1px' cellpadding='2px' bordercolor="#E5E5E5">
  131. <thead cellpadding='2px' height='40px'>
  132. <tr>
  133. <th width='15%'>序号</th>
  134. <th width='65%'>默认值</th>
  135. <th width='20%'>操作</th>
  136. </tr>
  137. </thead>
  138. <tbody height='36px'>
  139. <tr v-for="(item, key) in setInputTable" :key="key">
  140. <td align="center">{{ key + 1 }}</td>
  141. <td>
  142. <el-input v-model="setInputTable[key].dictValue" size="mini" placeholder="请输入内容"></el-input>
  143. </td>
  144. <td align="center">
  145. <el-link type="warning" @click="deleteTable(key)">删除</el-link>
  146. </td>
  147. </tr>
  148. </tbody>
  149. </table>
  150. <div class="martop20 flexEnd marbottom10"><i
  151. style="padding-bottom: 10px;color:rgb(10, 134, 217);font-size:24px;cursor: pointer;" class="el-icon-circle-plus"
  152. @click="addTable()"></i></div>
  153. </div>
  154. <el-row style="text-align: center">
  155. <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="saveType()">保存设置</el-button>
  156. &nbsp;&nbsp;
  157. <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="saveType()">继续保存</el-button>
  158. </el-row>
  159. </div>
  160. </template>
  161. <script>
  162. import { dictionary, saveInput, getColByTabId } from "@/api/manager/AdjustForm";
  163. import { getExcelHtml } from '@/api/exctab/excelmodel'
  164. export default {
  165. props: ['pkeyId', 'htmlData','checkList','checkNameList'],
  166. computed: {
  167. myHtmlData: function () {
  168. return this.htmlData;
  169. },
  170. myCheckList: function () {
  171. return this.checkList;
  172. },
  173. myCheckNameList: function () {
  174. return this.checkNameList;
  175. },
  176. },
  177. watch: {
  178. myHtmlData: function (newV) {
  179. console.log(newV,'1111111111')
  180. if (newV.type) {
  181. if (newV.type == 'checkbox') {
  182. this.from.type = 'checkbox';
  183. this.setInputTable = newV.checkLabelDatas;
  184. } else if (newV.type == 'radio') {
  185. this.from.type = 'radio';
  186. this.setInputTable = newV.radioDatas;
  187. } else if (newV.type == 'select') {
  188. this.from.type = 'select';
  189. this.setInputTable = newV.selectDatas;
  190. }
  191. else if (newV.type == 'selectBox') {
  192. this.from.type = 'selectBox';
  193. this.setInputTable = newV.selectDatas;
  194. }
  195. } else {
  196. // this.from.type = '';
  197. this.setInputTable = [];
  198. }
  199. },
  200. checkNameList: {
  201. handler (vla,val) {
  202. let iCan=val.some(e => e.name === "警告")
  203. if(iCan||this.htmlData.name==='警告'){
  204. this.$message({
  205. type: "warning",
  206. message: "当前选中的元素未进行匹配,不能设置输入框格式"
  207. });
  208. return;
  209. }
  210. },
  211. deep: true
  212. },
  213. },
  214. data() {
  215. return {
  216. elementName: [],
  217. kjtype: [],//框架类型
  218. from: {
  219. type: '',
  220. value: '',
  221. divide_c:'至',
  222. divide_y:'文本',
  223. divide_h:'文本',
  224. },
  225. setInputTable: [],//数据体
  226. disabled: false,
  227. yearList:[
  228. {name:'年',value:'YYYY',sort:1},
  229. {name:'月',value:'MM',sort:2},
  230. {name:'日',value:'DD',sort:3},
  231. ],
  232. yearSort:[],
  233. TimeSort:[],
  234. timeList:[
  235. {name:'时',value:'HH',sort:4},
  236. {name:'分',value:'mm',sort:5},
  237. {name:'秒',value:'ss',sort:6},
  238. ],
  239. checkDateList: [],
  240. checkTimeist:[],
  241. }
  242. },
  243. methods: {
  244. addTable() {//添加table表
  245. this.setInputTable.push({ dictValue: '' })
  246. },
  247. deleteTable(key) {//删除数据
  248. this.setInputTable.splice(key, 1)
  249. },
  250. saveType() {//保存设置按钮
  251. if (this.htmlData.tr === ''&&this.checkList.length==0 || this.htmlData.td === ''&&this.checkList.length==0) {
  252. this.$message({
  253. type: "warning",
  254. message: "请先选择元素"
  255. });
  256. return;
  257. }
  258. this.disabled = true
  259. if (this.from.type) {
  260. let ks = false
  261. if (this.from.type == 'select' | this.from.type == 'radio' | this.from.type == 'checkbox' | this.from.type == 'selectBox') {
  262. if (this.setInputTable) {
  263. this.setInputTable.forEach(val => {
  264. if (!val.dictValue) {
  265. ks = true
  266. }
  267. })
  268. }
  269. if (ks) {
  270. this.$message({
  271. type: "error",
  272. message: "请填写完枚举值"
  273. });
  274. this.disabled = false
  275. } else {
  276. if(this.checkList.length===0){
  277. this.saveInput([{
  278. trIndex: this.htmlData.tr,
  279. tdIndex: this.htmlData.td,
  280. tableId: this.pkeyId,
  281. textId: this.from.type,
  282. type: '1',
  283. textInfo: this.setInputTable
  284. }])
  285. }else if(this.checkList.length>0){
  286. let arr=[]
  287. this.checkList.forEach((ele)=>{
  288. arr.push({
  289. trIndex: ele.tr,
  290. tdIndex: ele.td,
  291. tableId: this.pkeyId,
  292. textId: this.from.type,
  293. type: '1',
  294. textInfo: this.setInputTable
  295. })
  296. })
  297. this.saveInput(arr)
  298. }
  299. }
  300. } else if(this.from.type == 'daterange'|this.from.type == 'date'){
  301. let c = this.yearSort.concat(this.TimeSort);//c=[1,2,3,4,5,6]
  302. console.log(c,'c');
  303. let isAdd=this.isContinuityNum(c)
  304. console.log(isAdd,'isAdd');
  305. if(isAdd||c.length===1){
  306. let dateFormat=[]
  307. this.yearList.forEach((ele)=>{
  308. this.checkDateList.forEach((ele1)=>{
  309. if(ele.value===ele1){
  310. dateFormat.push(
  311. {
  312. name:ele.name,
  313. value:ele.value
  314. }
  315. )
  316. }
  317. })
  318. })
  319. this.timeList.forEach((ele)=>{
  320. this.checkTimeist.forEach((ele1)=>{
  321. if(ele.value===ele1){
  322. dateFormat.push(
  323. {
  324. name:ele.name,
  325. value:ele.value
  326. }
  327. )
  328. }
  329. })
  330. })
  331. if(this.from.divide_y){
  332. dateFormat.push({
  333. name:'divide_y',value:this.from.divide_y
  334. })
  335. }
  336. if(this.from.divide_h){
  337. dateFormat.push({
  338. name:'divide_h',value:this.from.divide_h
  339. })
  340. }
  341. if(this.from.divide_c&&this.from.type==='daterange'){
  342. dateFormat.push({
  343. name:'divide_c',value:this.from.divide_c
  344. })
  345. }
  346. console.log(dateFormat,'dateFormat');
  347. if(this.checkList.length===0){
  348. this.saveInput([{
  349. trIndex: this.htmlData.tr,
  350. tdIndex: this.htmlData.td,
  351. tableId: this.pkeyId,
  352. textId: this.from.type,
  353. type: '1',
  354. textInfo: this.setInputTable,
  355. dateFormat:dateFormat
  356. }])
  357. }else if(this.checkList.length>0){
  358. let arr=[]
  359. this.checkList.forEach((ele)=>{
  360. arr.push({
  361. trIndex: ele.tr,
  362. tdIndex: ele.td,
  363. tableId: this.pkeyId,
  364. textId: this.from.type,
  365. type: '1',
  366. textInfo: this.setInputTable,
  367. dateFormat:dateFormat
  368. })
  369. })
  370. this.saveInput(arr)
  371. }
  372. }else{
  373. this.$message.warning('请按年月日时分秒顺序选择,不要跨越选择')
  374. }
  375. }
  376. else {
  377. if(this.checkList.length===0){
  378. this.saveInput([{
  379. trIndex: this.htmlData.tr,
  380. tdIndex: this.htmlData.td,
  381. tableId: this.pkeyId,
  382. textId: this.from.type,
  383. type: '1',
  384. textInfo: this.setInputTable
  385. }])
  386. }else if(this.checkList.length>0){
  387. let arr=[]
  388. this.checkList.forEach((ele)=>{
  389. arr.push({
  390. trIndex: ele.tr,
  391. tdIndex: ele.td,
  392. tableId: this.pkeyId,
  393. textId: this.from.type,
  394. type: '1',
  395. textInfo: this.setInputTable
  396. })
  397. })
  398. this.saveInput(arr)
  399. }
  400. }
  401. } else {
  402. this.disabled = false
  403. this.$message({
  404. type: "warning",
  405. message: "请选择文本格式"
  406. });
  407. }
  408. },
  409. async dictionary() {//获取文本类型接口
  410. const { data: res } = await dictionary()
  411. console.log(res);
  412. if (res.code === 200) {
  413. this.kjtype = res.data
  414. }
  415. },
  416. async saveInput(da) {//保存设置文本接口
  417. const { data: res } = await saveInput(da)
  418. console.log(res);
  419. this.checkDateList=[]
  420. this.checkTimeist=[]
  421. this.from.divide_y='文本'
  422. this.from.divide_h='文本'
  423. this.from.divide_c='至'
  424. this.yearSort=[]
  425. this.TimeSort=[]
  426. this.checkList=[]
  427. this.checkNameList=[]
  428. this.$emit('change')
  429. if (res.code == 200) {
  430. this.setInputTable = []
  431. this.disabled = false
  432. this.getExcelHtml()
  433. }
  434. },
  435. // async getColByTabId () {//获取字段信息
  436. // const { data: res } = await getColByTabId({ tabId: this.pkeyId })
  437. // console.log(res);
  438. // if (res.code === 200) {
  439. // this.elementName = res.data
  440. // }
  441. // },
  442. async getExcelHtml() {
  443. const { data: res } = await getExcelHtml({ pkeyId: this.pkeyId })
  444. console.log(res);
  445. if (res.code === 200) {
  446. this.htmlData.name = ''
  447. // this.from.type = ''
  448. this.htmlData.tr = ''
  449. this.htmlData.td = ''
  450. this.setInputTable = []
  451. localStorage.setItem('excelHtml', res.data)
  452. this.$emit('cop')
  453. }
  454. },
  455. // 判断是否是是
  456. //判断一串数字是否是连续的
  457. isContinuityNum(num){
  458. let array=[];
  459. if(num instanceof Array){
  460. array = [...num];
  461. }else{
  462. array = Array.from(num.toString())//转换为数组
  463. }
  464. var i=array[0];
  465. var isContinuation=true;
  466. for(var e in array){
  467. if(array[e]!=i){
  468. isContinuation=false;
  469. break;
  470. }
  471. i++;
  472. }
  473. return isContinuation;
  474. },
  475. changeDate(val){
  476. this.yearSort=[]
  477. this.yearList.forEach((ele)=>{
  478. val.forEach((ele1)=>{
  479. if(ele.value===ele1){
  480. this.yearSort.push(ele.sort)
  481. }
  482. })
  483. })
  484. },
  485. changeTime(val){
  486. this.TimeSort=[]
  487. this.timeList.forEach((ele)=>{
  488. val.forEach((ele1)=>{
  489. if(ele.value===ele1){
  490. this.TimeSort.push(ele.sort)
  491. }
  492. })
  493. })
  494. }
  495. },
  496. created() {
  497. this.dictionary() //获取文本类型接口
  498. // this.getColByTabId()
  499. },
  500. }
  501. </script>
  502. <style lang="scss" scoped>
  503. .table {
  504. margin-top: 20px;
  505. border-radius: 5px;
  506. color: #101010;
  507. font-size: 14px;
  508. }
  509. .setInputcss {
  510. width: 90%;
  511. height: 100%;
  512. }
  513. </style>