index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="siteManage-main variableList">
  3. <!-- 筛选start -->
  4. <div class="filter-container mb-20">
  5. <div class="left">
  6. <div>
  7. <span class="" style="margin-right: 30px">
  8. 【{{ store.state.siteManageLabelCom }}】 站点的所有变量
  9. </span>
  10. <el-button icon="Plus" type="success" @click="addItem()"
  11. :disabled="store.state.authorities.indexOf('新增') == -1">
  12. 新增
  13. </el-button>
  14. <el-button icon="Refresh" type="primary">
  15. 同步配置到采集器
  16. </el-button>
  17. <a href="./static/伍继变量列表导入模板.xlsx" download class="downloadMb">模板下载</a>
  18. </div>
  19. <div style="display: flex; margin-top: 15px">
  20. <el-radio-group v-model="select" @change="(val) => { select = val, query() }"
  21. :disabled="store.state.authorities.indexOf('查询') == -1">
  22. <el-radio-button label="day" :value="1">模拟量</el-radio-button>
  23. <el-radio-button label="month" :value="2">状态量</el-radio-button>
  24. <el-radio-button label="year" :value="3">参数量</el-radio-button>
  25. </el-radio-group>
  26. <el-input v-model="variableName" placeholder="搜索变量名称" style="width: 200px; margin:0 20px"
  27. :disabled="store.state.authorities.indexOf('查询') == -1"></el-input>
  28. <el-button type="primary" icon="Search" class="search-button" @click="query()"
  29. :disabled="store.state.authorities.indexOf('查询') == -1" style="margin: auto 0;">
  30. 搜索
  31. </el-button>
  32. </div>
  33. </div>
  34. <el-upload class="upload-demo" :action="fileUrl + 'deviceAnalogVariableList/variableListImport'"
  35. :on-progress="handleProgress" :on-success="handleUpAvatar" :on-error="handleError" multiple :limit="1" :headers="{
  36. accessToken: [accessToken],
  37. }" :file-list="fileList" style="margin: 0 10px 0 auto; display: inline-block"
  38. :disabled="store.state.authorities.indexOf('导入') == -1">
  39. <el-button type="primary" :disabled="store.state.authorities.indexOf('导入') == -1">导入</el-button>
  40. </el-upload>
  41. <el-button type="primary" @click="DataReportExport()"
  42. :disabled="store.state.authorities.indexOf('导出') == -1">导出</el-button>
  43. </div>
  44. <!-- 筛选end -->
  45. <!-- 表格start -->
  46. <el-table :data="tableData" border stripe :default-sort="{ prop: 'date', order: 'descending' }">
  47. <el-table-column type="index" label="序号" width="80px" sortable></el-table-column>
  48. <el-table-column prop="variableName" label="变量名" width="150px" sortable></el-table-column>
  49. <el-table-column prop="variableCoding" label="变量编号" width="150px" sortable></el-table-column>
  50. <el-table-column prop="monitorDeviceName" label="监控设备" width="150px"></el-table-column>
  51. <el-table-column prop="deviceName" label="通信设备" width=""></el-table-column>
  52. <el-table-column prop="dataAddress" label="数据地址" width=""></el-table-column>
  53. <el-table-column prop="dataType" label="数据类型" width=""></el-table-column>
  54. <el-table-column prop="coefficient" label="系数" width=""></el-table-column>
  55. <el-table-column prop="saveCycle" label="存盘周期" width=""></el-table-column>
  56. <el-table-column fixed="right" label="操作" width="180">
  57. <template #default="scope">
  58. <el-button type="primary" size="small" @click.prevent="editRow(scope.row)"
  59. :disabled="store.state.authorities.indexOf('修改') == -1" link>
  60. 修改
  61. </el-button>
  62. <el-popconfirm confirm-button-text="是" cancel-button-text="否" icon="el-icon-info" icon-color="red" title="确定删除?"
  63. @confirm="handleDelete(scope.row)" @cancel="cancelEvent">
  64. <template #reference>
  65. <el-button type="danger" size="small" :disabled="store.state.authorities.indexOf('删除') == -1" link>
  66. 删除
  67. </el-button>
  68. </template>
  69. </el-popconfirm>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. <!-- 表格end -->
  74. <!-- 分页start -->
  75. <div class="paginationBlock">
  76. <el-pagination v-model:currentPage="currentPage" :page-sizes="[15, 20, 25, 30]" :page-size="pageSize"
  77. layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
  78. @current-change="handleCurrentChange" background></el-pagination>
  79. </div>
  80. <!-- 分页end -->
  81. <!--弹框组件开始-----------------------start-->
  82. <dialog-component ref="dialogComponentRef" :siteId="props.siteId" @handleSelect="query()"></dialog-component>
  83. <!--弹框组件开始-----------------------end-->
  84. </div>
  85. </template>
  86. <script setup>
  87. /*----------------------------------依赖引入-----------------------------------*/
  88. import { useStore } from 'vuex'
  89. import { ElMessage, ElNotification } from 'element-plus'
  90. import { ref, onMounted, watch, getCurrentInstance, reactive, toRefs, nextTick } from 'vue'
  91. /*----------------------------------接口引入-----------------------------------*/
  92. import * as api from '@/api/siteManage/variableList'
  93. /*----------------------------------组件引入-----------------------------------*/
  94. import DialogComponent from './dialogComponent'
  95. /*----------------------------------store引入-----------------------------------*/
  96. /*----------------------------------公共方法引入-----------------------------------*/
  97. /*----------------------------------公共变量-----------------------------------*/
  98. const store = useStore()
  99. const props = defineProps({
  100. siteId: Number,
  101. activeName: String,
  102. }) //数据双向绑定
  103. const emit = defineEmits([]);
  104. const { proxy } = getCurrentInstance();
  105. /*----------------------------------变量声明-----------------------------------*/
  106. const fileUrl = ref(window.PLATFROM_CONFIG.baseUrl)
  107. const fileList = ref([])
  108. const accessToken = ref(store.state.user.accessToken)
  109. const state = reactive({
  110. tableData: [],
  111. currentPage: 1,
  112. pageSize: 10,
  113. total: 0,
  114. variableName: ""
  115. })
  116. const { tableData, currentPage, pageSize, total, variableName } = toRefs(state)
  117. const select = ref(1)
  118. const handleProgress = (file, fileList) => {
  119. file
  120. if (
  121. !(
  122. fileList.raw.type ===
  123. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
  124. fileList.raw.type === 'application/vnd.ms-excel'
  125. )
  126. ) {
  127. ElMessage({
  128. message: '上传文件只能是 xls 和 xlsx 格式!',
  129. type: 'error',
  130. })
  131. return false
  132. } else {
  133. return true
  134. }
  135. }
  136. const handleUpAvatar = (res, file) => {
  137. fileList.value = []
  138. ElMessage.success({
  139. message: '导入成功',
  140. type: 'success',
  141. })
  142. query()
  143. }
  144. const handleError = (res) => {
  145. let myError = res.toString() //转字符串
  146. myError = myError.replace('Error: ', '') //去掉前面的
  147. myError = JSON.parse(myError) //转对象
  148. ElMessage.error({
  149. message: myError.msg,
  150. type: 'error',
  151. })
  152. }
  153. //是否删除 ---- 否
  154. const cancelEvent = () => {
  155. console.log('cancel!')
  156. }
  157. //查询变量列表
  158. function query() {
  159. api
  160. .variableList({
  161. size: pageSize.value,
  162. current: currentPage.value,
  163. dataArea: select.value,
  164. siteId: props.siteId,
  165. variableName: variableName.value,
  166. })
  167. .then((requset) => {
  168. if (requset.status === 'SUCCESS') {
  169. tableData.value = requset.data.records
  170. total.value = requset.data.total
  171. } else {
  172. ElMessage.error(requset.msg)
  173. }
  174. })
  175. }
  176. function Select(value) {
  177. select.value = value
  178. query()
  179. }
  180. // 添加操作
  181. function addItem() {
  182. proxy.$refs['dialogComponentRef'].openDialog({
  183. dialogTitle: '新增',
  184. tableItem: {
  185. deviceCode: "",
  186. monitoringEquipment: '',
  187. communicationEquipment: '',
  188. // dataArea:'1'
  189. }
  190. })
  191. }
  192. // 编辑操作
  193. function editRow(row) {
  194. proxy.$refs['dialogComponentRef'].openDialog({
  195. dialogTitle: '编辑',
  196. tableItem: {
  197. deviceCode: row.deviceCode,
  198. variableName: row.variableName,
  199. monitorDeviceName: row.monitorDeviceName,
  200. variableCoding: row.variableCoding,
  201. monitoringEquipment: row.monitoringEquipment,
  202. communicationEquipment: row.communicationEquipment,
  203. dataAddress: row.dataAddress,
  204. dataType: row.dataType,
  205. coefficient: row.coefficient,
  206. saveCycle: row.saveCycle,
  207. dataArea: row.dataArea.toString(),
  208. id: row.id
  209. }
  210. })
  211. }
  212. //删除操作
  213. function handleDelete(row) {
  214. api.variableListDel({ id: row.id }).then((requset) => {
  215. if (requset.status === 'SUCCESS') {
  216. ElMessage.success({
  217. message: '删除成功',
  218. type: 'success',
  219. })
  220. query()
  221. } else {
  222. ElMessage.error(requset.msg)
  223. }
  224. })
  225. }
  226. //导出
  227. function DataReportExport() {
  228. api
  229. .variableListExport({
  230. dataArea: select.value,
  231. siteId: props.siteId,
  232. variableName: variableName.value,
  233. })
  234. .then((requset) => {
  235. if (requset.status === 'SUCCESS') {
  236. window.location.href = window.PLATFROM_CONFIG.fileUrl + requset.data
  237. ElMessage.success({
  238. message: '导出成功',
  239. type: 'success',
  240. })
  241. } else {
  242. ElMessage.error(requset.msg)
  243. }
  244. })
  245. }
  246. const handleSizeChange = (val) => {
  247. pageSize.value = val
  248. query()
  249. }
  250. const handleCurrentChange = (val) => {
  251. currentPage.value = val
  252. query()
  253. }
  254. watch(
  255. () => props.activeName,
  256. (newVal) => {
  257. if (newVal == 'third' && props.siteId) {
  258. query()
  259. }
  260. }
  261. )
  262. onMounted(() => {
  263. if (store.state.goUrl == 3) {
  264. query()
  265. }
  266. })
  267. </script>
  268. <style lang="scss" scoped></style>