index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="system-dic-container">
  3. <el-card shadow="hover">
  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="产品名称" prop="name">
  7. <el-input v-model="tableData.param.name" placeholder="请输入产品名称" clearable size="default" style="width: 240px" @keyup.enter.native="typeList" />
  8. </el-form-item>
  9. <el-form-item label="设备类型" prop="deviceType">
  10. <el-input v-model="tableData.param.deviceType" placeholder="请输入设备类型" clearable size="default" style="width: 240px" @keyup.enter.native="typeList" />
  11. </el-form-item>
  12. <el-form-item label="发布状态" prop="status" style="width: 200px;">
  13. <el-select v-model="tableData.param.status" placeholder="发布状态" clearable size="default" style="width: 240px">
  14. <el-option label="已发布" :value="1" />
  15. <el-option label="未发布" :value="0" />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item label="创建时间" prop="dateRange">
  19. <el-date-picker v-model="tableData.param.dateRange" size="default" style="width: 240px" value-format="YYYY-MM-DD" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button size="default" type="primary" class="ml10" @click="typeList">
  23. <el-icon>
  24. <ele-Search />
  25. </el-icon>
  26. 查询
  27. </el-button>
  28. <el-button size="default" @click="resetQuery(queryRef)">
  29. <el-icon>
  30. <ele-Refresh />
  31. </el-icon>
  32. 重置
  33. </el-button>
  34. <el-button size="default" type="primary" class="ml10" @click="onOpenAddDic" v-auth="'add'">
  35. <el-icon>
  36. <ele-FolderAdd />
  37. </el-icon>
  38. 新增产品
  39. </el-button>
  40. <el-button size="default" type="danger" class="ml10" @click="onRowDel(null)" v-auth="'del'">
  41. <el-icon>
  42. <ele-Delete />
  43. </el-icon>
  44. 删除
  45. </el-button>
  46. </el-form-item>
  47. </el-form>
  48. </div>
  49. <el-table :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange" v-loading="tableData.loading">
  50. <el-table-column type="selection" width="55" align="center" />
  51. <!-- <el-table-column label="ID" align="center" prop="id" width="60" v-col="'id'"/>-->
  52. <el-table-column label="标识" prop="key" :show-overflow-tooltip="true" v-col="'key'" />
  53. <el-table-column label="名称" prop="name" :show-overflow-tooltip="true" v-col="'name'" />
  54. <el-table-column label="分类" prop="categoryName" :show-overflow-tooltip="true" v-col="'categoryName'" />
  55. <!-- <el-table-column label="部门" prop="deptName" :show-overflow-tooltip="true" v-col="'deptName'"/> -->
  56. <el-table-column label="消息协议" prop="messageProtocol" :show-overflow-tooltip="true" v-col="'messageProtocol'" />
  57. <el-table-column label="接入方式" prop="transportProtocol" :show-overflow-tooltip="true" v-col="'transportProtocol'" />
  58. <el-table-column label="类型" prop="deviceType" :show-overflow-tooltip="true" v-col="'deviceType'" />
  59. <el-table-column prop="status" label="状态" width="100" align="center" v-col="'status'">
  60. <template #default="scope">
  61. <el-tag type="success" size="small" v-if="scope.row.status">已发布</el-tag>
  62. <el-tag type="info" size="small" v-else>未发布</el-tag>
  63. </template>
  64. </el-table-column>
  65. <!-- <el-table-column prop="createdAt" label="创建时间" align="center" width="180"></el-table-column> -->
  66. <el-table-column label="操作" width="150" align="center" fixed="right">
  67. <template #default="scope">
  68. <router-link :to="'/iotmanager/device/product/detail/' + scope.row.id" class="link-type" style="padding-right: 12px;font-size: 12px;color: #409eff;">
  69. <span>详情</span>
  70. </router-link>
  71. <el-button size="small" text type="warning" @click="onOpenEditDic(scope.row)" v-auth="'edit'">修改</el-button>
  72. <el-button size="small" text type="danger" @click="onRowDel(scope.row)" v-auth="'del'">删除</el-button>
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. <pagination v-show="tableData.total>0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="typeList" />
  77. </el-card>
  78. <EditDic ref="editDicRef" @typeList="typeList" />
  79. </div>
  80. </template>
  81. <script lang="ts">
  82. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  83. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  84. import EditDic from './component/editPro.vue';
  85. import api from '/@/api/device';
  86. // 定义接口来定义对象的类型
  87. interface TableDataRow {
  88. id: number;
  89. name: string;
  90. deviceType: string;
  91. status: number;
  92. desc: string;
  93. createBy: string;
  94. }
  95. interface TableDataState {
  96. ids: number[];
  97. tableData: {
  98. data: Array<TableDataRow>;
  99. total: number;
  100. loading: boolean;
  101. param: {
  102. pageNum: number;
  103. pageSize: number;
  104. name: string;
  105. deviceType: string;
  106. status: string;
  107. dateRange: string[];
  108. };
  109. };
  110. }
  111. export default defineComponent({
  112. name: 'deviceproduct',
  113. components: { EditDic },
  114. setup() {
  115. const addDicRef = ref();
  116. const editDicRef = ref();
  117. const queryRef = ref();
  118. const state = reactive<TableDataState>({
  119. ids: [],
  120. tableData: {
  121. data: [],
  122. total: 0,
  123. loading: false,
  124. param: {
  125. pageNum: 1,
  126. pageSize: 10,
  127. dictName: '',
  128. dictType: '',
  129. status: '',
  130. dateRange: [],
  131. },
  132. },
  133. });
  134. // 初始化表格数据
  135. const initTableData = () => {
  136. typeList();
  137. };
  138. const typeList = () => {
  139. state.tableData.loading = true;
  140. api.product.getList(state.tableData.param).then((res: any) => {
  141. state.tableData.data = res.product;
  142. state.tableData.total = res.total;
  143. }).finally(() => (state.tableData.loading = false));
  144. };
  145. // 打开新增产品弹窗
  146. const onOpenAddDic = () => {
  147. editDicRef.value.openDialog();
  148. };
  149. // 打开修改产品弹窗
  150. const onOpenEditDic = (row: TableDataRow) => {
  151. editDicRef.value.openDialog(row);
  152. };
  153. // 删除产品
  154. const onRowDel = (row: TableDataRow) => {
  155. let msg = '你确定要删除所选数据?';
  156. let ids: number[] = [];
  157. if (row) {
  158. msg = `此操作将永久删除产品:“${row.name}”,是否继续?`;
  159. ids = [row.id];
  160. } else {
  161. ids = state.ids;
  162. }
  163. if (ids.length === 0) {
  164. ElMessage.error('请选择要删除的数据。');
  165. return;
  166. }
  167. ElMessageBox.confirm(msg, '提示', {
  168. confirmButtonText: '确认',
  169. cancelButtonText: '取消',
  170. type: 'warning',
  171. })
  172. .then(() => {
  173. api.product.delete(ids).then(() => {
  174. ElMessage.success('删除成功');
  175. typeList();
  176. });
  177. })
  178. .catch(() => { });
  179. };
  180. // 页面加载时
  181. onMounted(() => {
  182. initTableData();
  183. });
  184. /** 重置按钮操作 */
  185. const resetQuery = (formEl: FormInstance | undefined) => {
  186. if (!formEl) return;
  187. formEl.resetFields();
  188. typeList();
  189. };
  190. // 多选框选中数据
  191. const handleSelectionChange = (selection: TableDataRow[]) => {
  192. state.ids = selection.map((item) => item.id);
  193. };
  194. return {
  195. addDicRef,
  196. editDicRef,
  197. queryRef,
  198. onOpenAddDic,
  199. onOpenEditDic,
  200. onRowDel,
  201. typeList,
  202. resetQuery,
  203. handleSelectionChange,
  204. ...toRefs(state),
  205. };
  206. },
  207. });
  208. </script>