From bdf652ac26ca4ec9f9155dce3168d116967a097b Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: Sun, 18 Oct 2020 11:05:39 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
constant/UrlConstant.js | 2 +-
constant/url.js | 2 +-
pages/notice/detail/noticeDetail.vue | 93 ++++++++++++++--------------
utils/ImageUtil.js | 54 ++++++++++++++++
utils/StringUtil.js | 44 ++++++++++++-
5 files changed, 147 insertions(+), 48 deletions(-)
create mode 100644 utils/ImageUtil.js
diff --git a/constant/UrlConstant.js b/constant/UrlConstant.js
index 887b50b..55208e7 100644
--- a/constant/UrlConstant.js
+++ b/constant/UrlConstant.js
@@ -6,7 +6,7 @@
// 服务器域名
// const baseUrl = 'https://app.demo.winqi.cn/';
const baseUrl = '/';
-const hcBaseUrl = 'https://hc.demo.winqi.cn'; // 登录接口
+const hcBaseUrl = '/'; // 登录接口
const loginUrl = baseUrl + 'app/loginProperty';
const areaUrl = baseUrl + "app/area.listAreas";
diff --git a/constant/url.js b/constant/url.js
index c228154..20163cd 100644
--- a/constant/url.js
+++ b/constant/url.js
@@ -1,5 +1,5 @@
const baseUrl = '/';
-const hcBaseUrl = 'https://hc.demo.winqi.cn'; // 登录接口
+const hcBaseUrl = '/'; // 登录接口
export default {
baseUrl: baseUrl,
hcBaseUrl: hcBaseUrl, // 登录接口
diff --git a/pages/notice/detail/noticeDetail.vue b/pages/notice/detail/noticeDetail.vue
index 6e111eb..cce3184 100644
--- a/pages/notice/detail/noticeDetail.vue
+++ b/pages/notice/detail/noticeDetail.vue
@@ -1,21 +1,21 @@
-
-
-
- {{notice.title}}
-
-
-
-
-
-
-
-
-
+
+
+
+ {{notice.title}}
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
+ .notice {
+ margin: 10rpx 7rpx;
+ padding: 25rpx;
+ background-color: #ffffff;
+ border-radius: 7rpx;
+ }
+
+ .title {
+ border-bottom: 1rpx solid #dedede;
+ font-weight: 700;
+ font-size: 34rpx;
+ color: #00AA00;
+ }
+
+ .content {
+ padding: 15rpx 0;
+ font-size: 25rpx;
+ color: #7B7B7B;
+ }
+
+ .footer {
+ padding: 15rpx 0;
+ font-size: 22rpx;
+ color: #ADADAD;
+ }
+
diff --git a/utils/ImageUtil.js b/utils/ImageUtil.js
new file mode 100644
index 0000000..f59df67
--- /dev/null
+++ b/utils/ImageUtil.js
@@ -0,0 +1,54 @@
+import {
+ isEmpty
+} from './StringUtil'
+/**
+ * 处理富文本里的图片宽度自适应
+ * 1.去掉img标签里的style、width、height属性
+ * 2.img标签添加style属性:max-width:100%;height:auto
+ * 3.修改所有style里的width属性为max-width:100%
+ * 4.去掉
标签
+ * @param html
+ * @returns {void|string|*}
+ */
+export function formatRichText(html) {
+ let newContent = html.replace(/
]*>/gi, function(match, capture) {
+ match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
+ match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
+ match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
+ return match;
+ });
+ newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
+ match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
+ return match;
+ });
+ newContent = newContent.replace(/
]*\/>/gi, '');
+ newContent = newContent.replace(/\
]*src=['"]([^'"]+)[^>]*>/g; // img 标签取src里面内容的正则
+ let s = _content.match(b); // 取到所有img标签 放到数组 s里面
+ if (!isEmpty(s)) {
+ for (let i = 0; i < s.length; i++) {
+ let srcImg = s[i].replace(b, '$1'); //取src面的内容
+ if (srcImg.slice(0, 4) == 'http' || srcImg.slice(0, 5) == 'https') {
+ //若src前4位置或者前5位是http、https则不做任何修改
+ } else {
+ //修改富文本字符串内容 img标签src 相对路径改为绝对路径
+ _content = _content.replace(srcImg, _url + srcImg);
+ }
+ }
+ }
+
+ return formatRichText(_content);
+}
diff --git a/utils/StringUtil.js b/utils/StringUtil.js
index 443ec33..dfec5ea 100644
--- a/utils/StringUtil.js
+++ b/utils/StringUtil.js
@@ -21,7 +21,49 @@ const isNotNull = function(_obj){
return true;
}
+/**
+ * 字符串工具类
+ *
+ * add by 吴学文 2020-09-25
+ */
+
+/**
+ * 判断是否为空
+ * @param {Object} _value 字符串
+ */
+const isEmpty=function (_value) {
+ let type = typeof _value;
+
+ switch (type) {
+ case 'number':
+ if (isFinite(_value)) {
+ if (_value == 0) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return true;
+ }
+ case 'object':
+ for (let i in _value) {
+ return false;
+ }
+ return true;
+ case 'string':
+ if (_value.length == 0) {
+ return true;
+ } else {
+ return false
+ }
+ default:
+ return true
+ }
+}
+
+
module.exports = {
isNull: isNull,
- isNotNull: isNotNull
+ isNotNull: isNotNull,
+ isEmpty:isEmpty
};
\ No newline at end of file