motif.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <!-- -->
  2. <template>
  3. <div class="motif_box">
  4. <el-card :style="'height:' + fullHeight + 'px'">
  5. <ul class="motif_ul">
  6. <li class="motif_list">
  7. <div class="list_left">系统LOGO:</div>
  8. <div class="list_right">
  9. <!-- <img v-viewer id="viewerDom" src="../../assets/images/newImg/12.jpg" alt="" class="" /> -->
  10. <img
  11. v-if="objData.logo_url"
  12. v-viewer
  13. id="viewerDom"
  14. :src="
  15. objData.logo_url.indexOf('http') == -1
  16. ? this.$deriveData + objData.logo_url
  17. : objData.logo_url
  18. "
  19. alt=""
  20. class=""
  21. />
  22. </div>
  23. </li>
  24. <li class="motif_list">
  25. <div class="list_left">系统名称:</div>
  26. <div class="list_right">{{ objData.sys_name }}</div>
  27. </li>
  28. <li class="motif_list">
  29. <div class="list_left">版权信息:</div>
  30. <div class="list_right">
  31. {{ objData.copyright_info }}
  32. </div>
  33. </li>
  34. <li>
  35. <el-button
  36. size="mini"
  37. type="primary"
  38. @click="btnEdit"
  39. style="margin: 10px 0 0 100px"
  40. >编辑</el-button
  41. >
  42. </li>
  43. </ul>
  44. </el-card>
  45. <!-- 编辑弹框 -->
  46. <el-dialog
  47. title="编辑"
  48. :visible.sync="redactVisible"
  49. width="50%"
  50. :close-on-click-modal="false"
  51. :close-on-press-escape="false"
  52. >
  53. <el-form ref="form" :rules="rules" :model="form" label-width="100px">
  54. <el-form-item label="系统LOGO:" prop="img">
  55. <el-upload
  56. class="avatar-uploader"
  57. ref="upload"
  58. :http-request="ImgUploadSectionFile"
  59. :with-credentials="true"
  60. :auto-upload="true"
  61. accept=".png, .jpg, .gif, .svg"
  62. action
  63. :on-change="handleChange"
  64. list-type="list"
  65. :file-list="fileList"
  66. multiple
  67. :show-file-list="false"
  68. >
  69. <img v-if="form.img" :src="form.img" class="avatar" />
  70. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  71. </el-upload>
  72. </el-form-item>
  73. <el-form-item label="系统名称: " prop="name">
  74. <el-input
  75. style="width: 80%"
  76. size="mini"
  77. v-model.trim="form.name"
  78. ></el-input>
  79. </el-form-item>
  80. <el-form-item label="版权信息: " prop="role_describe">
  81. <el-input
  82. style="width: 80%"
  83. size="mini"
  84. type="textarea"
  85. resize="none"
  86. v-model.trim="form.role_describe"
  87. ></el-input>
  88. </el-form-item>
  89. <el-form-item>
  90. <el-button
  91. :disabled="submitBtn"
  92. size="small"
  93. type="primary"
  94. @click="confirm"
  95. >{{ submitBtn == true ? "发布中..." : "发布" }}</el-button
  96. >
  97. <el-button size="small" @click="redactVisible = false"
  98. >取消</el-button
  99. >
  100. </el-form-item>
  101. </el-form>
  102. </el-dialog>
  103. </div>
  104. </template>
  105. <script>
  106. export default {
  107. //import引入的组件需要注入到对象中才能使用
  108. components: {},
  109. data() {
  110. //这里存放数据
  111. return {
  112. fullHeight: document.documentElement.clientHeight - 116, //
  113. redactVisible: false,
  114. form: {
  115. img: "",
  116. name: "",
  117. role_describe: ""
  118. },
  119. rules: {
  120. img: [{ required: true, message: "请上传系统LOGO", trigger: "blur" }],
  121. name: [{ required: true, message: "请输入系统名称", trigger: "blur" }],
  122. role_describe: [
  123. { required: true, message: "请输入版本信息", trigger: "blur" }
  124. ]
  125. },
  126. // 上传图片
  127. fileList: [],
  128. userDetail: {},
  129. objData: {},
  130. submitBtn: false // 防止弹框确定按钮重复请求
  131. };
  132. },
  133. //监听属性 类似于data概念
  134. computed: {},
  135. //监控data中的数据变化
  136. watch: {
  137. fullHeight(val) {
  138. //监控浏览器高度变化
  139. if (!this.timer) {
  140. this.fullHeight = val;
  141. this.timer = true;
  142. let that = this;
  143. setTimeout(function() {
  144. //防止过度调用监测事件,导致卡顿
  145. that.timer = false;
  146. }, 400);
  147. }
  148. },
  149. redactVisible(val) {
  150. if (val == false) {
  151. this.form.img = "";
  152. this.form.name = "";
  153. this.form.role_describe = "";
  154. }
  155. }
  156. },
  157. //方法集合
  158. methods: {
  159. //动态获取浏览器高度
  160. get_boderHeight() {
  161. const that = this;
  162. window.onresize = () => {
  163. return (() => {
  164. window.fullHeight = document.documentElement.clientHeight;
  165. that.fullHeight = window.fullHeight;
  166. })();
  167. };
  168. },
  169. // 上传图片
  170. ImgUploadSectionFile(param) {
  171. let that = this;
  172. let formData = new FormData();
  173. formData.append("img_file", param.file); //首页图片
  174. that
  175. .$axios({
  176. method: "post",
  177. url: "api/api_gateway?method=monitor_manage.cbd_manage.add_img",
  178. data: formData
  179. })
  180. .then(res => {
  181. if (res.data.data.src !== "0") {
  182. that.imageSrc = res.data.data.src;
  183. that.form.img = res.data.data.src;
  184. } else {
  185. that.$message.error({
  186. message: "上传图片失败,请重试",
  187. duration: 1500
  188. });
  189. }
  190. })
  191. .catch(err => {
  192. console.log(err);
  193. });
  194. // that.clearUploadBox();
  195. },
  196. handleChange(file, fileList) {
  197. if (!/\.(gif|jpg|jpeg|png|bmp|GIF|JPG|PNG)$/.test(file.raw.name)) {
  198. alert("图片类型必须是.gif,jpeg,jpg,png,bmp中的一种");
  199. return false;
  200. }
  201. let reader = new FileReader();
  202. reader.onload = e => {
  203. let data;
  204. if (typeof e.target.result === "object") {
  205. // 把Array Buffer转化为blob 如果是base64不需要
  206. data = window.URL.createObjectURL(new Blob([e.target.result]));
  207. } else {
  208. data = e.target.result;
  209. }
  210. };
  211. reader.readAsArrayBuffer(file.raw);
  212. this.fileList = fileList;
  213. },
  214. // 按钮编辑
  215. btnEdit() {
  216. this.form.img = this.$deriveData + this.objData.logo_url;
  217. this.form.name = this.objData.sys_name;
  218. this.form.role_describe = this.objData.copyright_info;
  219. this.redactVisible = true;
  220. },
  221. // 编辑确定
  222. confirm() {
  223. this.$refs["form"].validate(valid => {
  224. if (valid) {
  225. this.submitBtn = true;
  226. this.$axios({
  227. method: "POST",
  228. url: "/api/api_gateway?method=sysmenage.usermanager.theme_modify",
  229. data: this.qs.stringify({
  230. logo_url: this.form.img, // logo链接地址
  231. sys_name: this.form.name, // 系统名称
  232. copyright_info: this.form.role_describe // 版权信息
  233. })
  234. })
  235. .then(res => {
  236. if (res.data.data == true) {
  237. this.$message({
  238. message: "成功!",
  239. type: "success",
  240. duration: 1500
  241. });
  242. this.motifAxios();
  243. }
  244. this.submitBtn = false;
  245. this.redactVisible = false;
  246. })
  247. .catch(err => {
  248. // console.log(err);
  249. this.submitBtn = false;
  250. });
  251. } else {
  252. console.log("error submit!!");
  253. return false;
  254. }
  255. });
  256. },
  257. // 主题数据
  258. motifAxios() {
  259. this.$axios({
  260. method: "POST",
  261. url: "/api/api_gateway?method=sysmenage.usermanager.user_info"
  262. })
  263. .then(res => {
  264. console.log(res);
  265. this.objData = res.data.data.theme_info;
  266. })
  267. .catch(err => {
  268. console.log(err);
  269. });
  270. }
  271. },
  272. //生命周期 - 创建完成(可以访问当前this实例)
  273. created() {},
  274. //生命周期 - 挂载完成(可以访问DOM元素)
  275. mounted() {
  276. this.motifAxios();
  277. },
  278. beforeCreate() {}, //生命周期 - 创建之前
  279. beforeMount() {}, //生命周期 - 挂载之前
  280. beforeUpdate() {}, //生命周期 - 更新之前
  281. updated() {}, //生命周期 - 更新之后
  282. beforeDestroy() {}, //生命周期 - 销毁之前
  283. destroyed() {}, //生命周期 - 销毁完成
  284. activated() {} //如果页面有keep-alive缓存功能,这个函数会触发
  285. };
  286. </script>
  287. <style lang="less" scoped>
  288. // .motif_box {
  289. // }
  290. .motif_ul {
  291. .motif_list {
  292. display: flex;
  293. .list_left {
  294. width: 80px;
  295. text-align: right;
  296. font-size: 14px;
  297. color: #333333;
  298. font-weight: 400;
  299. }
  300. .list_right {
  301. width: 300px;
  302. margin: 0 0 30px 20px;
  303. font-size: 14px;
  304. img {
  305. width: 150px;
  306. height: 150px;
  307. border-radius: 5px;
  308. }
  309. }
  310. }
  311. }
  312. </style>