index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
  4. <el-form-item label="3d模型名称" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入3d模型名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <el-col :span="1.5">
  19. <el-button
  20. type="primary"
  21. plain
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. v-hasPermi="['data:model:add']"
  26. >新增</el-button>
  27. </el-col>
  28. <el-col :span="1.5">
  29. <el-button
  30. type="success"
  31. plain
  32. icon="el-icon-edit"
  33. size="mini"
  34. :disabled="single"
  35. @click="handleUpdate"
  36. v-hasPermi="['data:model:edit']"
  37. >修改</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="danger"
  42. plain
  43. icon="el-icon-delete"
  44. size="mini"
  45. :disabled="multiple"
  46. @click="handleDelete"
  47. v-hasPermi="['data:model:remove']"
  48. >删除</el-button>
  49. </el-col>
  50. <!-- <el-col :span="1.5">
  51. <el-button
  52. type="warning"
  53. plain
  54. icon="el-icon-download"
  55. size="mini"
  56. @click="handleExport"
  57. v-hasPermi="['data:model:export']"
  58. >导出</el-button>
  59. </el-col> -->
  60. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  61. </el-row>
  62. <el-table v-loading="loading" :data="modelList" @selection-change="handleSelectionChange">
  63. <el-table-column type="selection" width="55" align="center" />
  64. <el-table-column label="编号" align="center" prop="id" />
  65. <el-table-column label="3d模型名称" align="center" prop="name" />
  66. <el-table-column label="3d模型文件" align="center" prop="model3dFilePath">
  67. <template slot-scope="scope">
  68. <el-button
  69. size="mini"
  70. type="text"
  71. icon="el-icon-download"
  72. @click="download(scope.row.model3dFilePath)"
  73. v-hasPermi="['data:model:edit']"
  74. >{{ getFileName(scope.row.model3dFilePath) }}
  75. </el-button>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  79. <template slot-scope="scope">
  80. <el-button
  81. size="mini"
  82. type="text"
  83. icon="el-icon-edit"
  84. @click="handleUpdate(scope.row)"
  85. v-hasPermi="['data:model:edit']"
  86. >修改</el-button>
  87. <el-button
  88. size="mini"
  89. type="text"
  90. icon="el-icon-delete"
  91. @click="handleDelete(scope.row)"
  92. v-hasPermi="['data:model:remove']"
  93. >删除</el-button>
  94. </template>
  95. </el-table-column>
  96. </el-table>
  97. <pagination
  98. v-show="total>0"
  99. :total="total"
  100. :page.sync="queryParams.pageNum"
  101. :limit.sync="queryParams.pageSize"
  102. @pagination="getList"
  103. />
  104. <!-- 添加或修改3d模型对话框 -->
  105. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  106. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  107. <el-form-item label="3d模型名称" prop="name">
  108. <el-input v-model="form.name" placeholder="请输入3d模型名称" />
  109. </el-form-item>
  110. <!-- <el-form-item label="3d模型文件名称" prop="model3dFile">
  111. <file-upload v-model="form.model3dFile"/>
  112. </el-form-item> -->
  113. <el-form-item label="3d模型" prop="model3dFilePath">
  114. <file-upload v-model="form.model3dFilePath" :fileType="fileType" :fileSize="100" :limit="1"/>
  115. </el-form-item>
  116. </el-form>
  117. <div slot="footer" class="dialog-footer">
  118. <el-button type="primary" @click="submitForm">确 定</el-button>
  119. <el-button @click="cancel">取 消</el-button>
  120. </div>
  121. </el-dialog>
  122. </div>
  123. </template>
  124. <script>
  125. import { listModel, getModel, delModel, addModel, updateModel } from "@/api/data/model";
  126. export default {
  127. name: "Model",
  128. data() {
  129. return {
  130. // 遮罩层
  131. loading: true,
  132. // 选中数组
  133. ids: [],
  134. // 非单个禁用
  135. single: true,
  136. // 非多个禁用
  137. multiple: true,
  138. // 显示搜索条件
  139. showSearch: true,
  140. // 总条数
  141. total: 0,
  142. // 3d模型表格数据
  143. modelList: [],
  144. // 弹出层标题
  145. title: "",
  146. // 是否显示弹出层
  147. open: false,
  148. // 查询参数
  149. queryParams: {
  150. pageNum: 1,
  151. pageSize: 10,
  152. name: null,
  153. model3dFile: null,
  154. model3dFilePath: null,
  155. },
  156. // 表单参数
  157. form: {},
  158. // 表单校验
  159. rules: {
  160. name: [
  161. { required: true, message: "3d模型名称不能为空", trigger: "blur" }
  162. ],
  163. model3dFilePath: [
  164. { required: true, message: "3d模型不能为空", trigger: "blur" }
  165. ],
  166. },
  167. fileType: ['x_t', 'IGS'],
  168. };
  169. },
  170. created() {
  171. this.getList();
  172. },
  173. methods: {
  174. /** 查询3d模型列表 */
  175. getList() {
  176. this.loading = true;
  177. listModel(this.queryParams).then(response => {
  178. this.modelList = response.rows;
  179. this.total = response.total;
  180. this.loading = false;
  181. });
  182. },
  183. // 取消按钮
  184. cancel() {
  185. this.open = false;
  186. this.reset();
  187. },
  188. // 表单重置
  189. reset() {
  190. this.form = {
  191. id: null,
  192. name: null,
  193. model3dFile: null,
  194. model3dFilePath: null,
  195. createBy: null,
  196. createTime: null,
  197. updateBy: null,
  198. updateTime: null
  199. };
  200. this.resetForm("form");
  201. },
  202. /** 搜索按钮操作 */
  203. handleQuery() {
  204. this.queryParams.pageNum = 1;
  205. this.getList();
  206. },
  207. /** 重置按钮操作 */
  208. resetQuery() {
  209. this.resetForm("queryForm");
  210. this.handleQuery();
  211. },
  212. // 多选框选中数据
  213. handleSelectionChange(selection) {
  214. this.ids = selection.map(item => item.id)
  215. this.single = selection.length!==1
  216. this.multiple = !selection.length
  217. },
  218. /** 新增按钮操作 */
  219. handleAdd() {
  220. this.reset();
  221. this.open = true;
  222. this.title = "添加3d模型";
  223. },
  224. /** 修改按钮操作 */
  225. handleUpdate(row) {
  226. this.reset();
  227. const id = row.id || this.ids
  228. getModel(id).then(response => {
  229. this.form = response.data;
  230. this.open = true;
  231. this.title = "修改3d模型";
  232. });
  233. },
  234. /** 提交按钮 */
  235. submitForm() {
  236. this.$refs["form"].validate(valid => {
  237. if (valid) {
  238. if (this.form.id != null) {
  239. updateModel(this.form).then(response => {
  240. this.$modal.msgSuccess("修改成功");
  241. this.open = false;
  242. this.getList();
  243. });
  244. } else {
  245. addModel(this.form).then(response => {
  246. this.$modal.msgSuccess("新增成功");
  247. this.open = false;
  248. this.getList();
  249. });
  250. }
  251. }
  252. });
  253. },
  254. /** 删除按钮操作 */
  255. handleDelete(row) {
  256. const ids = row.id || this.ids;
  257. this.$modal.confirm('是否确认删除3d模型编号为"' + ids + '"的数据项?').then(function() {
  258. return delModel(ids);
  259. }).then(() => {
  260. this.getList();
  261. this.$modal.msgSuccess("删除成功");
  262. }).catch(() => {});
  263. },
  264. /** 导出按钮操作 */
  265. handleExport() {
  266. this.download('data/model/export', {
  267. ...this.queryParams
  268. }, `model_${new Date().getTime()}.xlsx`)
  269. },
  270. getFileName(path) {
  271. if (!path) {
  272. return ''
  273. } else if (path.lastIndexOf("/") > -1) {
  274. const newName = path.slice(path.lastIndexOf("/") + 1)
  275. const names = newName.split(".")
  276. if ((names.size = 2) && (names[0].length > 19)) {
  277. return newName.substring(0, names[0].length - 19) + '.' + names[1]
  278. } else {
  279. return newName
  280. }
  281. } else {
  282. return '';
  283. }
  284. },
  285. download(path) {
  286. this.$download.resource(path);
  287. }
  288. }
  289. };
  290. </script>