index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div class="system-dic-container">
  3. <el-card shadow="nover">
  4. <div class="system-user-search mb15">
  5. <el-form :model="tableData.param" ref="queryRef" :inline="true" label-width="68px">
  6. <el-form-item label="IP地址" prop="keyWord">
  7. <el-input v-model="tableData.param.keyWord" placeholder="请输入IP地址" clearable size="default" style="width: 240px" @keyup.enter.native="typeList" />
  8. </el-form-item>
  9. <!-- <el-form-item label="状态" prop="status" style="width: 200px;">
  10. <el-select v-model="tableData.param.status" placeholder="状态" clearable size="default" style="width: 240px">
  11. <el-option label="正常" :value="1" />
  12. <el-option label="停用" :value="0" />
  13. </el-select>
  14. </el-form-item> -->
  15. <el-form-item>
  16. <el-button size="default" type="primary" class="ml10" @click="typeList">
  17. <el-icon>
  18. <ele-Search />
  19. </el-icon>
  20. 查询
  21. </el-button>
  22. <el-button size="default" @click="resetQuery(queryRef)">
  23. <el-icon>
  24. <ele-Refresh />
  25. </el-icon>
  26. 重置
  27. </el-button>
  28. <el-button size="default" type="primary" class="ml10" @click="onOpenAdd" v-auth="'add'">
  29. <el-icon>
  30. <ele-FolderAdd />
  31. </el-icon>
  32. 新建
  33. </el-button>
  34. <el-button size="default" type="info" class="ml10" @click="onRowDel(null)" v-auth="'del'">
  35. <el-icon>
  36. <ele-Delete />
  37. </el-icon>
  38. 批量删除
  39. </el-button>
  40. </el-form-item>
  41. </el-form>
  42. </div>
  43. <el-table :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange" v-loading="tableData.loading">
  44. <el-table-column type="selection" width="55" align="center" />
  45. <!-- <el-table-column label="ID" align="center" prop="id" width="100" v-col="'id'"/>-->
  46. <!-- <el-table-column label="标识" prop="key" show-overflow-tooltip v-col="'key'" /> -->
  47. <el-table-column label="IP" prop="ip" v-col="'ip'"/>
  48. <!-- <el-table-column label="名称" prop="name" show-overflow-tooltip v-col="'name'" /> -->
  49. <el-table-column label="备注" prop="remark" show-overflow-tooltip v-col="'remark'"/>
  50. <!-- <el-table-column label="分类" prop="categoryName" show-overflow-tooltip v-col="'categoryName'" /> -->
  51. <el-table-column
  52. align="center"
  53. prop="status"
  54. label="状态"
  55. v-col="'status'"
  56. >
  57. <template #default="scope">
  58. <el-tag
  59. v-if="scope.row.status == 0"
  60. class="ml-2"
  61. type="info"
  62. >停用</el-tag>
  63. <el-tag
  64. v-else
  65. class="ml-2"
  66. type="success"
  67. >正常</el-tag>
  68. </template>
  69. </el-table-column>
  70. <el-table-column v-col="'createdAt'" prop="createdAt" label="创建时间" align="center" width="180"></el-table-column>
  71. <el-table-column v-col="'handle'" label="操作" width="150" align="center" fixed="right">
  72. <template #default="scope">
  73. <!-- <router-link :to="'/iotmanager/device/product/detail/' + scope.row.id" class="link-type" style="padding-right: 12px;font-size: 12px;color: #409eff;">
  74. <span>详情</span>
  75. </router-link> -->
  76. <el-button size="small" text type="warning" @click="onOpenEditDic(scope.row)" v-auth="'edit'">编辑</el-button>
  77. <el-button size="small" text type="info" @click="onRowDel(scope.row)" v-auth="'del'">删除</el-button>
  78. <el-popover
  79. placement="bottom"
  80. :width="154"
  81. trigger="click"
  82. >
  83. <template #reference>
  84. <el-button
  85. size="small"
  86. type="text"
  87. class="more-btn"
  88. @click="isShowMore = !isShowMore"
  89. v-auth="'more'"
  90. >更多
  91. <i
  92. style="margin-left: 2px;"
  93. :class="isShowMore ? 'fa fa-angle-down':'fa fa-angle-up'"
  94. ></i>
  95. </el-button>
  96. </template>
  97. <div class="more-opearte-wrap">
  98. <el-button
  99. @click="onChangeStatus(scope.row.id, 1)"
  100. :disabled="scope.row.status == 1"
  101. link
  102. size="small"
  103. key="success"
  104. type="success"
  105. v-auth="'on'"
  106. >设为启用</el-button>
  107. <el-divider direction="vertical" />
  108. <el-button
  109. @click="onChangeStatus(scope.row.id, 0)"
  110. :disabled="scope.row.status == 0"
  111. link
  112. size="small"
  113. key="warning"
  114. type="warning"
  115. v-auth="'off'"
  116. >设为禁用</el-button>
  117. </div>
  118. </el-popover>
  119. </template>
  120. </el-table-column>
  121. </el-table>
  122. <pagination v-show="tableData.total>0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="typeList" />
  123. </el-card>
  124. <EditDic ref="editDicRef" @typeList="typeList" />
  125. </div>
  126. </template>
  127. <script lang="ts">
  128. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  129. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  130. import EditDic from './component/editPro.vue';
  131. // import api from '/@/api/device';
  132. import api from '/@/api/system';// blackList
  133. // 定义接口来定义对象的类型
  134. interface TableDataRow {
  135. id: number;
  136. name: string;
  137. deviceType: string;
  138. status: number;
  139. desc: string;
  140. createBy: string;
  141. }
  142. interface TableDataState {
  143. ids: number[];
  144. tableData: {
  145. data: Array<TableDataRow>;
  146. total: number;
  147. loading: boolean;
  148. param: {
  149. pageNum: number;
  150. pageSize: number;
  151. keyWord: string;
  152. dateRange: string[];
  153. };
  154. };
  155. isShowMore: boolean
  156. }
  157. export default defineComponent({
  158. name: 'deviceproduct',
  159. components: { EditDic },
  160. setup() {
  161. const addDicRef = ref();
  162. const editDicRef = ref();
  163. const queryRef = ref();
  164. const state = reactive<TableDataState>({
  165. ids: [],
  166. tableData: {
  167. data: [],
  168. total: 0,
  169. loading: false,
  170. param: {
  171. pageNum: 1,
  172. pageSize: 10,
  173. keyWord: '',
  174. dateRange: [],
  175. },
  176. },
  177. isShowMore: true
  178. });
  179. // 初始化表格数据
  180. const initTableData = () => {
  181. typeList();
  182. };
  183. const typeList = () => {
  184. state.tableData.loading = true;
  185. state.tableData.data = [];
  186. state.tableData.total = 0;
  187. api.blackList.getList(state.tableData.param).then((res: any) => {
  188. state.tableData.data = res.list;
  189. state.tableData.total = res.total;
  190. }).finally(() => (state.tableData.loading = false));
  191. };
  192. // 改变状态
  193. const onChangeStatus = (id: number, status: number) => {
  194. api.blackList.changeStatus({ id: id, status: status }).then(() => {
  195. ElMessage.success(status == 1 ? '已开启' : '已关闭');
  196. typeList();
  197. })
  198. };
  199. // 打开新增产品弹窗
  200. const onOpenAdd = () => {
  201. editDicRef.value.openDialog();
  202. };
  203. // 打开修改产品弹窗
  204. const onOpenEditDic = (row: TableDataRow) => {
  205. editDicRef.value.openDialog(row);
  206. };
  207. // 删除产品
  208. const onRowDel = (row: TableDataRow) => {
  209. let msg = '你确定要删除所选数据?';
  210. let ids: number[] = [];
  211. if (row) {
  212. msg = `此操作将永久删除IP:“${row.ip}”,是否继续?`;
  213. ids = [row.id];
  214. } else {
  215. ids = state.ids;
  216. }
  217. if (ids.length === 0) {
  218. ElMessage.error('请选择要删除的数据。');
  219. return;
  220. }
  221. ElMessageBox.confirm(msg, '提示', {
  222. confirmButtonText: '确认',
  223. cancelButtonText: '取消',
  224. type: 'warning',
  225. })
  226. .then(() => {
  227. api.blackList.delete(ids).then(() => {
  228. ElMessage.success('删除成功');
  229. typeList();
  230. });
  231. })
  232. .catch(() => { });
  233. };
  234. // 页面加载时
  235. onMounted(() => {
  236. initTableData();
  237. });
  238. /** 重置按钮操作 */
  239. const resetQuery = (formEl: FormInstance | undefined) => {
  240. if (!formEl) return;
  241. formEl.resetFields();
  242. typeList();
  243. };
  244. // 多选框选中数据
  245. const handleSelectionChange = (selection: TableDataRow[]) => {
  246. state.ids = selection.map((item) => item.id);
  247. };
  248. return {
  249. addDicRef,
  250. editDicRef,
  251. queryRef,
  252. onChangeStatus,
  253. onOpenAdd,
  254. onOpenEditDic,
  255. onRowDel,
  256. typeList,
  257. resetQuery,
  258. handleSelectionChange,
  259. ...toRefs(state),
  260. };
  261. },
  262. });
  263. </script>