index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <template>
  2. <div class="sy-content">
  3. <el-row>
  4. <el-col>
  5. <!-- 操作按钮 -->
  6. <el-row class="czBtns">
  7. <el-col :span="1.5">
  8. <el-button
  9. type="primary"
  10. plain
  11. icon="el-icon-plus"
  12. size="mini"
  13. @click="handleAdd"
  14. >新增
  15. </el-button>
  16. </el-col>
  17. </el-row>
  18. <!-- 表格数据信息 -->
  19. <el-table
  20. ref="driverConfigTable"
  21. v-loading="loading"
  22. :data="driverConfigList"
  23. stripe
  24. border
  25. header-row-class-name="headBackground"
  26. >
  27. <el-table-column
  28. v-if="false"
  29. key="id"
  30. label="ID"
  31. align="center"
  32. prop="id"
  33. />
  34. <el-table-column
  35. v-if="false"
  36. key="clsId"
  37. label="clsId"
  38. align="center"
  39. prop="clsId"
  40. />
  41. <el-table-column
  42. key="driverName"
  43. label="驱动名称"
  44. align="center"
  45. prop="driverName"
  46. :show-overflow-tooltip="true"
  47. />
  48. <el-table-column
  49. label="操作"
  50. align="center"
  51. width="250"
  52. class-name="small-padding fixed-width"
  53. >
  54. <template v-if="scope.row.userId !== 1" slot-scope="scope">
  55. <el-button
  56. size="mini"
  57. type="text"
  58. icon="el-icon-edit"
  59. @click="handleUpdate(scope.row)"
  60. >修改
  61. </el-button>
  62. <el-button
  63. size="mini"
  64. type="text"
  65. icon="el-icon-delete"
  66. @click="handleDelete(scope.row)"
  67. >删除
  68. </el-button>
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. </el-col>
  73. </el-row>
  74. <!-- 添加或修改用户配置对话框 -->
  75. <el-dialog
  76. :title="title"
  77. :visible.sync="open"
  78. width="500px"
  79. append-to-body
  80. :close-on-click-modal="false"
  81. >
  82. <el-form ref="driverForm" :model="driverForm" :rules="rules" label-width="140px">
  83. <el-row style="margin-bottom: 5px">
  84. <el-col>
  85. <el-form-item label="驱动:" prop="driver">
  86. <el-select
  87. v-if="driverForm.id"
  88. v-model="driverForm.driver"
  89. placeholder="请选择驱动"
  90. style="width: 300px"
  91. disabled
  92. >
  93. <el-option
  94. v-for="dict in driverList"
  95. :key="dict.value"
  96. :label="dict.name"
  97. :value="dict"
  98. />
  99. </el-select>
  100. <el-select
  101. v-else
  102. v-model="driverForm.driver"
  103. placeholder="请选择驱动"
  104. style="width: 300px"
  105. >
  106. <el-option
  107. v-for="dict in driverList"
  108. :key="dict.value"
  109. :label="dict.name"
  110. :value="dict"
  111. />
  112. </el-select>
  113. </el-form-item>
  114. </el-col>
  115. <el-col :span="12">
  116. <el-form-item label="数据项名称:" prop="items" class="cy-item-name">
  117. <el-tag
  118. v-for="tag in dynamicTags"
  119. :key="tag.itemName"
  120. closable
  121. :disable-transitions="false"
  122. @close="handleTagClose(tag)"
  123. >
  124. {{ tag.itemName }}
  125. </el-tag>
  126. <el-input
  127. v-if="inputVisible"
  128. ref="saveTagInput"
  129. v-model="inputValue"
  130. class="input-new-tag"
  131. size="small"
  132. @keyup.enter.native="handleInputConfirm"
  133. @blur="handleInputConfirm"
  134. />
  135. <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 添加</el-button>
  136. </el-form-item>
  137. </el-col>
  138. </el-row>
  139. </el-form>
  140. <div slot="footer" class="dialog-footer" style="margin-top: 20px;">
  141. <el-button
  142. type="primary"
  143. size="mini"
  144. @click="submitForm"
  145. >确定
  146. </el-button>
  147. <el-button size="mini" @click="cancel">取消</el-button>
  148. </div>
  149. </el-dialog>
  150. </div>
  151. </template>
  152. <script>
  153. import {
  154. addDataSourceDriver, delDataSourceDriver,
  155. getAllDataSourceDriver,
  156. getDriverItemById,
  157. getOpcDaDriverEnum,
  158. updateDataSourceDriver
  159. } from '@/api/system/driver'
  160. export default {
  161. name: 'Index',
  162. components: {},
  163. data() {
  164. return {
  165. // 遮罩层
  166. loading: true,
  167. // 驱动配置数据
  168. driverConfigList: [],
  169. // 驱动数据
  170. driverList: [],
  171. // 弹出层标题
  172. title: '',
  173. // 是否显示弹出层
  174. open: false,
  175. inputVisible: false,
  176. inputValue: '',
  177. dynamicTags: [],
  178. driverForm: {
  179. id: null,
  180. driver: null,
  181. items: null
  182. },
  183. // 表单验证
  184. rules: {
  185. driver: [
  186. {
  187. required: true,
  188. message: '驱动不能为空',
  189. pattern: '[^ \x22]+',
  190. trigger: 'change'
  191. }
  192. ],
  193. items: [
  194. {
  195. required: true,
  196. message: '数据项不能为空',
  197. pattern: '[^ \x22]+',
  198. trigger: 'blur'
  199. }
  200. ]
  201. }
  202. }
  203. },
  204. created() {
  205. this.getDriverConfigList()
  206. },
  207. methods: {
  208. /** 查询所有数据源配置信息 */
  209. getDriverConfigList() {
  210. this.loading = true
  211. getAllDataSourceDriver().then((response) => {
  212. const data = response.data
  213. this.driverConfigList = data
  214. this.loading = false
  215. })
  216. },
  217. /** 删除按钮操作 */
  218. handleDelete(row) {
  219. this.$confirm('您确定要删除该驱动配置吗?', '系统提示', {
  220. confirmButtonText: '确定',
  221. cancelButtonText: '取消',
  222. cancelButtonClass: 'btn_custom_cancel',
  223. closeOnClickModal: false,
  224. type: 'warning'
  225. }).then(() => {
  226. delDataSourceDriver(row.id).then((res) => {
  227. if (res.code === 200) {
  228. this.$message({
  229. message: '删除成功',
  230. type: 'success'
  231. })
  232. this.getDriverConfigList()
  233. }
  234. })
  235. }).catch(() => {
  236. })
  237. },
  238. /** 修改按钮操作 */
  239. handleUpdate(row) {
  240. this.getOpcDaDriverEnum((res) => {
  241. getDriverItemById(row.id).then((res) => {
  242. this.open = true
  243. this.title = '驱动数据项属性配置'
  244. const data = res.data
  245. this.driverForm = {
  246. id: data.id,
  247. driver: {
  248. 'name': data.driverName,
  249. 'value': data.clsId
  250. }
  251. }
  252. this.dynamicTags = data.driverBasicItemList
  253. })
  254. })
  255. },
  256. /** 新增按钮操作 */
  257. handleAdd() {
  258. this.reset()
  259. this.open = true
  260. this.title = '驱动数据项属性配置'
  261. this.getOpcDaDriverEnum()
  262. },
  263. /** 表单提交 */
  264. submitForm() {
  265. if (!this.driverForm.driver) {
  266. this.$message({
  267. message: '请选择驱动',
  268. type: 'warning'
  269. })
  270. return
  271. }
  272. if (!this.dynamicTags || this.dynamicTags.length === 0) {
  273. this.$message({
  274. message: '请添加数据项',
  275. type: 'warning'
  276. })
  277. return
  278. }
  279. const params = {
  280. driverName: this.driverForm.driver.name,
  281. clsId: this.driverForm.driver.value,
  282. driverBasicItemList: []
  283. }
  284. this.dynamicTags.forEach((tag) => {
  285. params.driverBasicItemList.push({
  286. id: tag.id,
  287. driverId: tag.driverId,
  288. itemName: tag.itemName
  289. })
  290. })
  291. if (this.driverForm.id) {
  292. params.id = this.driverForm.id
  293. updateDataSourceDriver(params).then((response) => {
  294. if (response.code === 200) {
  295. this.$message({
  296. message: '修改成功',
  297. type: 'success'
  298. })
  299. this.getDriverConfigList()
  300. this.cancel()
  301. }
  302. })
  303. return
  304. }
  305. addDataSourceDriver(params).then((response) => {
  306. if (response.code === 200) {
  307. this.$message({
  308. message: '保存成功',
  309. type: 'success'
  310. })
  311. this.getDriverConfigList()
  312. this.cancel()
  313. }
  314. })
  315. },
  316. /** 查询所有驱动信息 */
  317. getOpcDaDriverEnum(callback) {
  318. getOpcDaDriverEnum().then((res) => {
  319. const data = res.data
  320. const drivers = []
  321. for (const key in data) {
  322. drivers.push({
  323. 'name': key,
  324. 'value': data[key]
  325. })
  326. }
  327. this.driverList = drivers
  328. if (callback) callback(data)
  329. })
  330. },
  331. /** 移除数据项 */
  332. handleTagClose(tag) {
  333. this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
  334. },
  335. /** 显示数据项输入框 */
  336. showInput() {
  337. this.inputVisible = true
  338. this.$nextTick(_ => {
  339. this.$refs.saveTagInput.$refs.input.focus()
  340. })
  341. },
  342. /** 数据项输入完成事件 */
  343. handleInputConfirm() {
  344. const inputValue = this.inputValue
  345. if (inputValue) {
  346. const isInArray = this.dynamicTags.some(item => item.itemName === inputValue)
  347. if (!isInArray) {
  348. this.dynamicTags.push({
  349. itemName: inputValue
  350. })
  351. }
  352. }
  353. this.inputVisible = false
  354. this.inputValue = ''
  355. },
  356. /** 表单重置 */
  357. reset() {
  358. this.dynamicTags = []
  359. this.driverForm = {
  360. id: null,
  361. driver: null,
  362. items: null
  363. }
  364. if (this.$refs['driverForm']) {
  365. this.$refs['driverForm'].resetFields()
  366. }
  367. },
  368. /** 表单重置 */
  369. cancel() {
  370. this.open = false
  371. this.reset()
  372. }
  373. }
  374. }
  375. </script>
  376. <style rel="stylesheet/scss" lang="scss">
  377. .el-tag + .el-tag {
  378. margin-left: 10px;
  379. }
  380. .button-new-tag {
  381. margin-left: 10px;
  382. height: 32px;
  383. line-height: 30px;
  384. padding-top: 0;
  385. padding-bottom: 0;
  386. }
  387. .input-new-tag {
  388. width: 90px;
  389. margin-left: 10px;
  390. vertical-align: bottom;
  391. }
  392. .cy-item-name {
  393. .el-form-item__content {
  394. position: absolute;
  395. height: 110px;
  396. overflow: auto;
  397. }
  398. }
  399. </style>