index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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="success" 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="'/device/product/detail/' + scope.row.id" class="link-type" style="padding-right: 12px;
  69. font-size: 12px;color: #409eff;">
  70. <span>详情</span>
  71. </router-link>
  72. <el-button size="small" text type="warning" @click="onOpenEditDic(scope.row)" v-auth="'edit'">修改</el-button>
  73. <el-button size="small" text type="danger" @click="onRowDel(scope.row)" v-auth="'del'">删除</el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <pagination v-show="tableData.total>0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="typeList" />
  78. </el-card>
  79. <EditDic ref="editDicRef" @typeList="typeList" />
  80. </div>
  81. </template>
  82. <script lang="ts">
  83. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  84. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  85. import EditDic from './component/editPro.vue';
  86. import api from '/@/api/device';
  87. // 定义接口来定义对象的类型
  88. interface TableDataRow {
  89. id: number;
  90. name: string;
  91. deviceType: string;
  92. status: number;
  93. desc: string;
  94. createBy: string;
  95. }
  96. interface TableDataState {
  97. ids: number[];
  98. tableData: {
  99. data: Array<TableDataRow>;
  100. total: number;
  101. loading: boolean;
  102. param: {
  103. pageNum: number;
  104. pageSize: number;
  105. name: string;
  106. deviceType: string;
  107. status: string;
  108. dateRange: string[];
  109. };
  110. };
  111. }
  112. export default defineComponent({
  113. name: 'deviceproduct',
  114. components: { EditDic },
  115. setup() {
  116. const addDicRef = ref();
  117. const editDicRef = ref();
  118. const queryRef = ref();
  119. const state = reactive<TableDataState>({
  120. ids: [],
  121. tableData: {
  122. data: [],
  123. total: 0,
  124. loading: false,
  125. param: {
  126. pageNum: 1,
  127. pageSize: 10,
  128. dictName: '',
  129. dictType: '',
  130. status: '',
  131. dateRange: [],
  132. },
  133. },
  134. });
  135. // 初始化表格数据
  136. const initTableData = () => {
  137. typeList();
  138. };
  139. const typeList = () => {
  140. state.tableData.loading = true;
  141. api.product.getList(state.tableData.param).then((res: any) => {
  142. console.log(res);
  143. state.tableData.data = res.product;
  144. state.tableData.total = res.total;
  145. }).finally(() => (state.tableData.loading = false));
  146. };
  147. // 打开新增产品弹窗
  148. const onOpenAddDic = () => {
  149. editDicRef.value.openDialog();
  150. };
  151. // 打开修改产品弹窗
  152. const onOpenEditDic = (row: TableDataRow) => {
  153. editDicRef.value.openDialog(row);
  154. };
  155. // 删除产品
  156. const onRowDel = (row: TableDataRow) => {
  157. let msg = '你确定要删除所选数据?';
  158. let ids: number[] = [];
  159. if (row) {
  160. msg = `此操作将永久删除产品:“${row.name}”,是否继续?`;
  161. ids = [row.id];
  162. } else {
  163. ids = state.ids;
  164. }
  165. if (ids.length === 0) {
  166. ElMessage.error('请选择要删除的数据。');
  167. return;
  168. }
  169. ElMessageBox.confirm(msg, '提示', {
  170. confirmButtonText: '确认',
  171. cancelButtonText: '取消',
  172. type: 'warning',
  173. })
  174. .then(() => {
  175. api.product.delete(ids).then(() => {
  176. ElMessage.success('删除成功');
  177. typeList();
  178. });
  179. })
  180. .catch(() => {});
  181. };
  182. // 页面加载时
  183. onMounted(() => {
  184. initTableData();
  185. });
  186. /** 重置按钮操作 */
  187. const resetQuery = (formEl: FormInstance | undefined) => {
  188. if (!formEl) return;
  189. formEl.resetFields();
  190. typeList();
  191. };
  192. // 多选框选中数据
  193. const handleSelectionChange = (selection: TableDataRow[]) => {
  194. state.ids = selection.map((item) => item.id);
  195. };
  196. return {
  197. addDicRef,
  198. editDicRef,
  199. queryRef,
  200. onOpenAddDic,
  201. onOpenEditDic,
  202. onRowDel,
  203. typeList,
  204. resetQuery,
  205. handleSelectionChange,
  206. ...toRefs(state),
  207. };
  208. },
  209. });
  210. </script>