IconLibraryManagement.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. getIcon(); // icon 更新
  118. resolve();
  119. } else {
  120. that.$checkRequestCode(result);
  121. reject();
  122. }
  123. })
  124. .catch((err) => {
  125. loading.close();
  126. that.$message({
  127. type: "warning",
  128. message: "上传失败,请稍后重试!",
  129. });
  130. reject();
  131. });
  132. });
  133. },
  134. delIcon(item) {
  135. let that = this;
  136. this.$confirm("此操作将永久删除该图标, 是否继续?", "提示", {
  137. confirmButtonText: "确定",
  138. cancelButtonText: "取消",
  139. type: "warning",
  140. })
  141. .then(() => {
  142. // 调用删除图标接口 更新列表 getIcon()
  143. const loading = that.$createLoading("图标删除中,请稍后!")
  144. iconApi
  145. .delIcon({ id: item.id })
  146. .then((result) => {
  147. loading.close();
  148. if (result.code == 200) {
  149. getIcon(); // icon 更新
  150. } else {
  151. that.$checkRequestCode(result);
  152. }
  153. })
  154. .catch((err) => {
  155. loading.close();
  156. that.$message({
  157. type: "warning",
  158. message: "更新失败,请稍后重试!",
  159. });
  160. });
  161. })
  162. .catch(() => {
  163. that.$message({
  164. type: "info",
  165. message: "已取消删除",
  166. });
  167. });
  168. },
  169. updateIcon(params) {
  170. let that = this;
  171. // 更新图标后更新列表 getIcon()
  172. const loading = this.$createLoading("图标信息更新中,请稍后!")
  173. return new Promise((resolve, reject) => {
  174. iconApi
  175. .updateIcon(params)
  176. .then((result) => {
  177. loading.close();
  178. if (result.code == 200) {
  179. getIcon(); // icon 更新
  180. resolve();
  181. } else {
  182. that.$checkRequestCode(result);
  183. reject();
  184. }
  185. })
  186. .catch((err) => {
  187. loading.close();
  188. that.$message({
  189. type: "warning",
  190. message: "更新失败,请稍后重试!",
  191. });
  192. reject();
  193. });
  194. });
  195. },
  196. changeIconType(type) {
  197. let arr = this.iconTotalList.filter(function (item) {
  198. if (type == 99999) return true;
  199. if (item.type == type) {
  200. return true;
  201. } else {
  202. return false;
  203. }
  204. });
  205. this.iconShowList = JSON.parse(JSON.stringify(arr));
  206. },
  207. },
  208. computed: {
  209. iconData() {
  210. return this.$store.state.iconList;
  211. },
  212. layerData() {
  213. return this.$store.state.layerList;
  214. },
  215. },
  216. watch: {
  217. iconData: {
  218. immediate: true,
  219. handler(newVal, oldName) {
  220. if (newVal) {
  221. let arr = [];
  222. newVal.map(function (obj) {
  223. obj.url = systemConfig.iconImageUrl + obj.iconUuidName;
  224. arr.push(JSON.parse(JSON.stringify(obj)));
  225. });
  226. this.iconTotalList = JSON.parse(JSON.stringify(arr));
  227. this.iconShowList = JSON.parse(JSON.stringify(arr));
  228. }
  229. },
  230. },
  231. layerData: {
  232. immediate: true,
  233. handler(newVal, oldName) {
  234. if (newVal) this.layerList = this.layerList.concat(newVal);
  235. },
  236. },
  237. },
  238. };
  239. </script>
  240. <style lang="less" scoped>
  241. .content {
  242. width: 100%;
  243. .el-header {
  244. background: #ffffff;
  245. margin-bottom: 20px;
  246. padding-top: 10px;
  247. .el-select {
  248. margin-right: 10px;
  249. }
  250. }
  251. .el-main {
  252. background: #ffffff;
  253. overflow: hidden;
  254. overflow-y: auto;
  255. box-sizing: content-box;
  256. ul {
  257. overflow: hidden;
  258. }
  259. li {
  260. width: 69px;
  261. height: 71px;
  262. margin: 0px 10px;
  263. float: left;
  264. padding: 5px 5px;
  265. padding-bottom: 50px;
  266. position: relative;
  267. cursor: pointer;
  268. img {
  269. width: 69px;
  270. height: 71px;
  271. }
  272. .name {
  273. position: absolute;
  274. width: 100%;
  275. bottom: 24px;
  276. left: 0px;
  277. text-align: center;
  278. overflow: hidden;
  279. white-space: nowrap;
  280. text-overflow: ellipsis;
  281. }
  282. .func {
  283. position: absolute;
  284. bottom: 3px;
  285. left: 21px;
  286. display: none;
  287. .el-button {
  288. border: 0px;
  289. padding: 0 0;
  290. background: transparent;
  291. }
  292. }
  293. &:hover {
  294. .func {
  295. display: inline-block;
  296. }
  297. }
  298. }
  299. }
  300. }
  301. </style>