index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <div
  3. style="width: 98%;display: flex;align-items: center;justify-content: space-between;padding-top: 1%;margin-left: 1%;">
  4. <div style="font-size: 20px;">
  5. 模型应用
  6. </div>
  7. <div style="display: flex;">
  8. <el-input size="mini" v-model="dcName" style="width: 100%;margin-left: 1%;" placeholder="搜索项目"/>
  9. <el-button type="primary" @click="showAdd" size="mini" style="margin-left:5%;" :icon="Plus">新增</el-button>
  10. </div>
  11. </div>
  12. <div
  13. style="width: 98%;display: flex;align-items: center;justify-content: space-between;padding-top: 1%;margin-left: 1%;">
  14. <el-select
  15. v-model="formJi"
  16. class="noBorSel"
  17. placeholder="全部"
  18. style="width: 10%;margin-left: 0%;"
  19. >
  20. <el-option label="全部" :value="1"/>
  21. <el-option label="已发布" :value="2"/>
  22. </el-select>
  23. </div>
  24. <div
  25. style="height: 70vh;width: 98%;margin-left:1%;background-color: transparent;margin-top: 1%;display: flex;flex-wrap: wrap;justify-content: flex-start;gap: 0.65%">
  26. <div v-for="(item,index) in modelList">
  27. <div class="coz-card" @mouseenter="setHoverIndex(index)" @click="goFlow(item)" style="cursor: pointer;"
  28. @mouseleave="resetHoverIndex">
  29. <div style="display: flex;width: 100%;">
  30. <div style="margin-left: 8%;margin-top: 5%;width: 60%;font-size: 17px;">
  31. {{ item.appTitle }}
  32. <div style="margin-top: 10%;font-size: 16px;">
  33. 模型描述:{{ item.appNote }}
  34. </div>
  35. </div>
  36. <!-- <img style="width: 90px;height: 90px;margin-left: 0%;margin-top: 8%;border-radius: 12px;" :src="item.appIcon" v-if="item.appIcon!==null"
  37. alt="">
  38. <img style="width: 90px;height: 90px;margin-left: 0%;margin-top: 8%;border-radius: 12px;" v-if="item.appIcon==null" src="@/assets/images/defaultModel.png"
  39. alt=""> -->
  40. <img style="width: 90px;height: 90px;margin-left: 0%;margin-top: 8%;border-radius: 12px;" src="@/assets/images/defaultModel.png"
  41. alt="">
  42. </div>
  43. <div>
  44. <el-tag style="margin-left: 8%;margin-top: -1%;">应用</el-tag>
  45. </div>
  46. <div style="display: flex;align-items: center;margin-left: 8%;margin-top: 3%;line-height: 1.5;width: 85%;">
  47. <img style="width: 4%;height: 4%;border-radius: 13px;" src="@/assets/images/touxiang.png" alt="">
  48. <div style="margin-left: 3%;font-size: 12px;">
  49. 创建人:{{ item.createBy }} 更新时间:{{ item.createTime }}
  50. </div>
  51. <el-icon style="color: #79bbff;margin-left: auto;cursor: pointer;" @click.stop="handleBizDataShowConfig(item)"
  52. v-if="hoverIndex === index">
  53. <TrendCharts/>
  54. </el-icon>
  55. <el-icon style="color: #79bbff;margin-left: auto;cursor: pointer;" @click.stop="editModel(item)"
  56. v-if="hoverIndex === index">
  57. <Edit/>
  58. </el-icon>
  59. <el-icon style="color: red;margin-left: 2%;cursor: pointer;" @click.stop="delModel(item)"
  60. v-if="hoverIndex === index">
  61. <Delete/>
  62. </el-icon>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. <el-pagination
  68. v-if="total>12"
  69. small
  70. background
  71. style="margin-top: 0.8%;float: right;margin-right: 1%;"
  72. layout="prev, pager, next"
  73. :total="total"
  74. v-model="pageNum"
  75. @change="changePage"
  76. class="mt-4"
  77. />
  78. <el-dialog
  79. :title="title"
  80. v-model="isContentVisible"
  81. width="30%"
  82. @close="clearForm"
  83. >
  84. <div>
  85. <el-form ref="formAddref" :model="formAdd" label-width="100px" class="coz-mg-card" :rules="rulesAdd">
  86. <el-form-item label="模型名称:" prop="appTitle">
  87. <el-input v-model="formAdd.appTitle" placeholder="请输入应用名称"></el-input>
  88. </el-form-item>
  89. <el-form-item label="模型描述:" prop="appNote">
  90. <el-input type="textarea" v-model="formAdd.appNote" placeholder="请输入应用描述"></el-input>
  91. </el-form-item>
  92. <el-form-item label="图标:">
  93. <div style="display: flex;width: 100%;">
  94. <img v-if="!previewUrl" style="width: 80px;height:80px;margin-left: 0%;margin-top: 0%;border-radius: 12px;"
  95. src="@/assets/images/defaultModel.png" alt="">
  96. <img v-if="previewUrl" style="width: 80px;height:80px;margin-left: 0%;margin-top: 0%;border-radius: 12px;"
  97. :src="previewUrl" alt="">
  98. </div>
  99. <el-upload
  100. ref="uploadRef"
  101. style="margin-top: 3%;"
  102. :limit="1"
  103. :show-file-list="false"
  104. :file-list="fileList"
  105. :headers="upload.headers"
  106. :on-progress="handlepro"
  107. :on-success="handleFileSuccess"
  108. :on-change="handleChange"
  109. :action="upload.url + '?file=' + upload.updateSupport"
  110. :auto-upload="false"
  111. >
  112. <el-button slot="trigger" @click="clearDefault" plain type="primary" size="mini" style="margin-left:auto;width: 80px;"
  113. :icon="Upload">上传
  114. </el-button>
  115. </el-upload>
  116. </el-form-item>
  117. </el-form>
  118. </div>
  119. <template #footer>
  120. <el-button @click="isContentVisible = false">取消</el-button>
  121. <el-button v-if="isAdd" type="primary" @click="submitAdd">确定</el-button>
  122. <el-button v-if="!isAdd" type="primary" @click="subEdit">确定</el-button>
  123. </template>
  124. </el-dialog>
  125. </template>
  126. <script setup>
  127. import {onMounted, ref} from 'vue'
  128. import {Delete, Plus, Upload} from '@element-plus/icons-vue'
  129. import {addModeling, delModeling, editModeling, getModelingById, getModellist} from '@/api/standardization/modeling'
  130. import {getToken} from '@/utils/auth'
  131. import imagePath from '@/assets/images/defaultModel.png';
  132. import {useStore} from 'vuex';
  133. import router from "@/router/index.js";
  134. import defaultAvatar from '@/assets/images/defaultModel.png'
  135. const {proxy} = getCurrentInstance();
  136. const imageUrl = ref(defaultAvatar)
  137. const title = ref()
  138. const heightAll = window.innerHeight
  139. const isContentVisible = ref(false)
  140. const isAdd = ref(true)
  141. const pageNum = ref(1)
  142. const modelList = ref([])
  143. const total = ref(0)
  144. const hoverIndex = ref(-1)
  145. const uploadRef = ref()
  146. const fileList = ref([
  147. {
  148. name: '', // 文件名
  149. url: defaultAvatar , // 文件访问URL
  150. status: 'ready', // 文件状态:success-上传成功
  151. uid: new Date().getTime() // 唯一标识
  152. }
  153. ]);
  154. const formAdd = ref({
  155. appTitle: '',
  156. appNote: '',
  157. });
  158. const formAddref = ref()
  159. const rulesAdd = reactive({
  160. appTitle: [{required: true, message: '必填', trigger: 'blur'}],
  161. appNote: [{required: true, message: '必填', trigger: 'blur'}],
  162. });
  163. const parModel = ref({})
  164. const parFile = ref({})
  165. const upload = reactive({
  166. // 是否显示弹出层(用户导入)
  167. open: false,
  168. // 弹出层标题(用户导入)
  169. title: "",
  170. // 是否禁用上传
  171. isUploading: false,
  172. // 是否更新已经存在的用户数据
  173. updateSupport: '',
  174. // 设置上传的请求头部
  175. headers: {Authorization: "Bearer " + getToken()},
  176. // 上传的地址
  177. url: import.meta.env.VITE_APP_BASE_API + "/common/upload"
  178. });
  179. const previewUrl = ref()
  180. const store = useStore();
  181. const setHoverIndex = (index) => {
  182. hoverIndex.value = index;
  183. };
  184. const resetHoverIndex = () => {
  185. hoverIndex.value = -1;
  186. };
  187. function goFlow(item) {
  188. store.commit('setId', item.appId);
  189. proxy.$router.push({path: '/standardization/modeling'});
  190. }
  191. function clearForm(){
  192. formAdd.value = {}
  193. previewUrl.value = ''
  194. }
  195. function editModel(item) {
  196. parModel.value = item
  197. isAdd.value = false
  198. isContentVisible.value = true
  199. title.value = '修改模型应用'
  200. getModelingById(item.appId).then(res => {
  201. if (res.code === 200) {
  202. const parUrl = import.meta.env.VITE_APP_BASE_API
  203. formAdd.value.appTitle = res.data.appTitle
  204. formAdd.value.appNote = res.data.appNote
  205. formAdd.value.appId = res.data.appId
  206. formAdd.value.appIcon = parUrl + res.data.appIcon
  207. previewUrl.value = res.data.appIcon ? parUrl + res.data.appIcon : imagePath;
  208. console.log(previewUrl.value)
  209. } else {
  210. proxy.$message.error('获取模型详情失败');
  211. }
  212. }).catch(() => {
  213. proxy.$message.error('获取模型详情失败');
  214. });
  215. }
  216. function handleBizDataShowConfig(data) {
  217. router.push("/standardization/modeling/bizDataShowConfig/" + data.appId)
  218. }
  219. function subEdit() {
  220. if (parFile.value) {
  221. formAddref.value.validate(async (valid) => {
  222. if (valid) {
  223. editModeling(formAdd.value).then(res => {
  224. if (res.code === 200) {
  225. proxy.$message({
  226. message: '修改成功',
  227. type: 'success'
  228. });
  229. isContentVisible.value = false;
  230. getList();
  231. }
  232. })
  233. }
  234. })
  235. } else {
  236. }
  237. // formAddref.value.validate(async (valid) => {
  238. // if (valid) {
  239. // nextTick(() => {
  240. // uploadRef.value.submit();
  241. // });
  242. // }
  243. // })
  244. }
  245. function delModel(item) {
  246. proxy.$confirm('是否删除该模型应用?', '提示', {
  247. confirmButtonText: '确定',
  248. cancelButtonText: '取消',
  249. type: 'warning'
  250. }).then(() => {
  251. delModeling(item.appId).then(res => {
  252. if (res.code === 200) {
  253. proxy.$message({
  254. message: '删除成功',
  255. type: 'success'
  256. });
  257. getList();
  258. } else {
  259. proxy.$message.error('删除失败');
  260. }
  261. })
  262. }).catch(() => {
  263. });
  264. }
  265. function submitAdd() {
  266. if (parFile.value) {
  267. formAddref.value.validate(async (valid) => {
  268. if (valid) {
  269. addModeling(formAdd.value).then(res => {
  270. if (res.code === 200) {
  271. proxy.$message({
  272. message: '新增成功',
  273. type: 'success'
  274. });
  275. isContentVisible.value = false;
  276. getList();
  277. } else {
  278. proxy.$message.error('新增失败');
  279. }
  280. })
  281. }
  282. })
  283. } else {
  284. formAddref.value.validate(async (valid) => {
  285. if (valid) {
  286. nextTick(() => {
  287. uploadRef.value.submit();
  288. });
  289. }
  290. })
  291. }
  292. // formAddref.value.validate(async (valid) => {
  293. // if (valid) {
  294. // nextTick(() => {
  295. // uploadRef.value.submit();
  296. // });
  297. // }
  298. // })
  299. }
  300. function handleFileSuccess(response, file, fileList) {
  301. console.log("上传成功的响应:", response);
  302. if (response.code === 200) {
  303. if (isAdd.value === true) {
  304. formAdd.value.appIcon = response.fileName
  305. addModeling(formAdd.value).then(res => {
  306. if (res.code === 200) {
  307. proxy.$message({
  308. message: '新增成功',
  309. type: 'success'
  310. });
  311. isContentVisible.value = false;
  312. getList();
  313. } else {
  314. proxy.$message.error('新增失败');
  315. }
  316. }).catch(() => {
  317. proxy.$message.error('新增失败');
  318. });
  319. } else {
  320. formAdd.value.appIcon = response.fileName
  321. editModeling(formAdd.value).then(res => {
  322. if (res.code === 200) {
  323. proxy.$message({
  324. message: '修改成功',
  325. type: 'success'
  326. });
  327. isContentVisible.value = false;
  328. getList();
  329. } else {
  330. proxy.$message.error('修改失败');
  331. }
  332. }).catch(() => {
  333. proxy.$message.error('修改失败');
  334. });
  335. }
  336. }
  337. };
  338. function clearDefault() {
  339. uploadRef.value.clearFiles();
  340. }
  341. function handleChange(file, fileList) {
  342. parFile.value = file
  343. const rawFile = file.raw;
  344. previewUrl.value = URL.createObjectURL(rawFile);
  345. }
  346. function showAdd() {
  347. isAdd.value = true
  348. isContentVisible.value = true
  349. title.value = '新增模型应用'
  350. }
  351. function changePage(val) {
  352. console.log(val)
  353. pageNum.value = val,
  354. getList()
  355. }
  356. function getList() {
  357. var par = {
  358. pageSize: 12,
  359. pageNum: pageNum.value,
  360. }
  361. getModellist(par).then(res => {
  362. modelList.value = res.rows
  363. total.value = res.total
  364. modelList.value.forEach(item=>{
  365. item.appIcon = item.appIcon
  366. })
  367. })
  368. }
  369. onMounted(() => {
  370. getList()
  371. })
  372. </script>
  373. <style scoped>
  374. :deep(.el-upload .el-upload--picture-card) {
  375. height: 100px !important;
  376. width: 100px !important;
  377. }
  378. .coz-card {
  379. margin-top: 5%;
  380. height: 20vh;
  381. width: 24vw;
  382. border-radius: 6px;
  383. border: 1px solid;
  384. border-style: solid;
  385. overflow: hidden;
  386. border-color: #e9e9eb;
  387. transition: all 150ms ease-out;
  388. }
  389. .coz-card:hover {
  390. box-shadow: 0 10px 12px 0 rgba(28, 31, 35, 0.06);
  391. }
  392. /* 自定义类名需保留 */
  393. .coz-stroke-primary {
  394. stroke: var(--primary-color); /* 需替换为实际颜色值 */
  395. }
  396. .coz-mg-card {
  397. margin: 10px; /* 根据实际需求调整 */
  398. }
  399. </style>