index.vue 12 KB

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