IconLibraryManagement.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <el-container :class="'content'">
  3. <el-header>
  4. <el-select
  5. v-model="selectValue"
  6. @change="changeIconType"
  7. placeholder="请选择"
  8. >
  9. <el-option
  10. v-for="item in layerList"
  11. :key="item.id"
  12. :label="item.name"
  13. :value="item.id"
  14. >
  15. </el-option>
  16. </el-select>
  17. <el-button type="primary" class="add-item" @click="openAddIconDialog">
  18. 新增图标
  19. </el-button>
  20. </el-header>
  21. <el-main>
  22. <ul>
  23. <li
  24. v-for="(item, index) in iconShowList"
  25. :key="index"
  26. :title="item.iconChieseName"
  27. >
  28. <!-- :style="{ backgroundImage: 'url(' + item.url + ')' }" -->
  29. <img :src="item.url" alt="" srcset="" />
  30. <div class="name">
  31. {{ item.iconChieseName }}
  32. </div>
  33. <div class="func">
  34. <el-button
  35. icon="el-icon-edit"
  36. :title="'修改'"
  37. @click="openUpdateIconDialog(item)"
  38. ></el-button>
  39. <el-button
  40. icon="el-icon-delete"
  41. :title="'删除'"
  42. @click="delIcon(item)"
  43. ></el-button>
  44. </div>
  45. </li>
  46. </ul>
  47. </el-main>
  48. <Icon
  49. v-if="iconDialogIsShow"
  50. v-bind="{
  51. dialogVisible: iconDialogIsShow,
  52. title: iconDialogTitle,
  53. type: iconDialogType,
  54. iconInfo: iconInfo,
  55. beforeClose: closeIconDialog,
  56. addIconFunc: addNewIcon,
  57. updateIconFunc: updateIcon,
  58. }"
  59. ></Icon>
  60. </el-container>
  61. </template>
  62. <script>
  63. import iconApi from "@/api/icon";
  64. export default {
  65. components: {
  66. Icon: () => import("@/components/DataLayer/Icon.vue"),
  67. },
  68. data() {
  69. return {
  70. iconTotalList: [],
  71. iconShowList: [],
  72. iconDialogTitle: "",
  73. iconDialogIsShow: false,
  74. iconDialogType: 1, // 1 新增 2 修改
  75. iconInfo: undefined,
  76. selectValue: 99999,
  77. layerList: [
  78. {
  79. id: 99999,
  80. name: "全部",
  81. },
  82. ],
  83. };
  84. },
  85. created() {},
  86. methods: {
  87. openAddIconDialog() {
  88. this.iconDialogType = 1;
  89. this.iconInfo = undefined;
  90. this.iconDialogTitle = "新增图标";
  91. this.iconDialogIsShow = true;
  92. },
  93. openUpdateIconDialog(item) {
  94. this.iconDialogType = 2;
  95. this.iconInfo = {
  96. name: item.iconChieseName,
  97. id: item.id,
  98. type: item.type,
  99. url: location.origin + item.url,
  100. };
  101. this.iconDialogTitle = "修改图标";
  102. this.iconDialogIsShow = true;
  103. },
  104. closeIconDialog() {
  105. this.iconDialogIsShow = false;
  106. },
  107. addNewIcon(params) {
  108. let that = this;
  109. // 添加图标后更新列表 getIcon()
  110. const loading = this.$createLoading("图标上传增加中,请稍后!");
  111. return new Promise((resolve, reject) => {
  112. iconApi
  113. .addNewIcon(params)
  114. .then((result) => {
  115. loading.close();
  116. if (result.code == 200) {
  117. that.$message({
  118. type: "success",
  119. message: "图标上传增加成功!",
  120. });
  121. getIcon(); // icon 更新
  122. resolve();
  123. } else {
  124. that.$checkRequestCode(result);
  125. reject();
  126. }
  127. })
  128. .catch((err) => {
  129. loading.close();
  130. that.$message({
  131. type: "warning",
  132. message: "上传失败,请稍后重试!",
  133. });
  134. reject();
  135. });
  136. });
  137. },
  138. delIcon(item) {
  139. let that = this;
  140. this.$confirm("此操作将永久删除该图标, 是否继续?", "提示", {
  141. confirmButtonText: "确定",
  142. cancelButtonText: "取消",
  143. type: "warning",
  144. })
  145. .then(() => {
  146. // 调用删除图标接口 更新列表 getIcon()
  147. const loading = that.$createLoading("图标删除中,请稍后!");
  148. iconApi
  149. .delIcon({ id: item.id })
  150. .then((result) => {
  151. loading.close();
  152. if (result.code == 200) {
  153. that.$message({
  154. type: "success",
  155. message: "图标删除成功!",
  156. });
  157. getIcon(); // icon 更新
  158. } else {
  159. that.$checkRequestCode(result);
  160. }
  161. })
  162. .catch((err) => {
  163. loading.close();
  164. that.$message({
  165. type: "warning",
  166. message: "更新失败,请稍后重试!",
  167. });
  168. });
  169. })
  170. .catch(() => {
  171. that.$message({
  172. type: "info",
  173. message: "已取消删除",
  174. });
  175. });
  176. },
  177. updateIcon(params) {
  178. let that = this;
  179. // 更新图标后更新列表 getIcon()
  180. const loading = this.$createLoading("图标信息更新中,请稍后!");
  181. return new Promise((resolve, reject) => {
  182. iconApi
  183. .updateIcon(params)
  184. .then((result) => {
  185. loading.close();
  186. if (result.code == 200) {
  187. that.$message({
  188. type: "success",
  189. message: "图标信息更新成功!",
  190. });
  191. getIcon(); // icon 更新
  192. resolve();
  193. } else {
  194. that.$checkRequestCode(result);
  195. reject();
  196. }
  197. })
  198. .catch((err) => {
  199. loading.close();
  200. that.$message({
  201. type: "warning",
  202. message: "更新失败,请稍后重试!",
  203. });
  204. reject();
  205. });
  206. });
  207. },
  208. changeIconType(type) {
  209. let arr = this.iconTotalList.filter(function (item) {
  210. if (type == 99999) return true;
  211. if (item.type == type) {
  212. return true;
  213. } else {
  214. return false;
  215. }
  216. });
  217. this.iconShowList = JSON.parse(JSON.stringify(arr));
  218. },
  219. },
  220. computed: {
  221. iconData() {
  222. return this.$store.state.iconList;
  223. },
  224. layerData() {
  225. return this.$store.state.layerList;
  226. },
  227. },
  228. watch: {
  229. iconData: {
  230. immediate: true,
  231. handler(newVal, oldName) {
  232. if (newVal) {
  233. let arr = [];
  234. newVal.map(function (obj) {
  235. obj.url = systemConfig.iconImageUrl + obj.iconUuidName;
  236. arr.push(JSON.parse(JSON.stringify(obj)));
  237. });
  238. this.iconTotalList = JSON.parse(JSON.stringify(arr));
  239. this.iconShowList = JSON.parse(JSON.stringify(arr));
  240. }
  241. },
  242. },
  243. layerData: {
  244. immediate: true,
  245. handler(newVal, oldName) {
  246. if (newVal) this.layerList = this.layerList.concat(newVal);
  247. },
  248. },
  249. },
  250. };
  251. </script>
  252. <style lang="less" scoped>
  253. .content {
  254. width: 100%;
  255. .el-header {
  256. background: #ffffff;
  257. margin-bottom: 20px;
  258. padding-top: 10px;
  259. .el-select {
  260. margin-right: 10px;
  261. }
  262. }
  263. .el-main {
  264. background: #ffffff;
  265. overflow: hidden;
  266. overflow-y: auto;
  267. box-sizing: content-box;
  268. ul {
  269. overflow: hidden;
  270. }
  271. li {
  272. width: 69px;
  273. height: 71px;
  274. margin: 0px 10px;
  275. float: left;
  276. padding: 5px 5px;
  277. padding-bottom: 50px;
  278. position: relative;
  279. cursor: pointer;
  280. img {
  281. width: 69px;
  282. height: 71px;
  283. }
  284. .name {
  285. position: absolute;
  286. width: 100%;
  287. bottom: 24px;
  288. left: 0px;
  289. text-align: center;
  290. overflow: hidden;
  291. white-space: nowrap;
  292. text-overflow: ellipsis;
  293. }
  294. .func {
  295. position: absolute;
  296. bottom: 3px;
  297. left: 21px;
  298. display: none;
  299. .el-button {
  300. border: 0px;
  301. padding: 0 0;
  302. background: transparent;
  303. }
  304. }
  305. &:hover {
  306. .func {
  307. display: inline-block;
  308. }
  309. }
  310. }
  311. }
  312. }
  313. </style>