|
@@ -1,106 +1,66 @@
|
|
|
+// pages/usernotice/usernotice.js
|
|
|
Page({
|
|
|
+
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- noticeDetail: {
|
|
|
- content: ''
|
|
|
- },
|
|
|
- phoneNumbers: [] // 存储提取出的电话号码
|
|
|
+
|
|
|
},
|
|
|
|
|
|
- // 处理电话号码,将电话号码转换为可点击的链接
|
|
|
- processPhoneNumbers: function(content) {
|
|
|
- if (!content) return '';
|
|
|
-
|
|
|
- // 匹配带区号的固定电话号码(如:0516-87030707)和手机号码
|
|
|
- const phoneRegex = /(?:0\d{2,3}-\d{7,8}|1[3-9]\d{9})/g;
|
|
|
- const phoneNumbers = [];
|
|
|
-
|
|
|
- // 将内容中的电话号码替换为蓝色文本
|
|
|
- let processedContent = content;
|
|
|
-
|
|
|
- // 找到所有匹配的电话号码,从后向前替换,避免位置变化
|
|
|
- const matches = [];
|
|
|
- let match;
|
|
|
- while ((match = phoneRegex.exec(content)) !== null) {
|
|
|
- matches.push({
|
|
|
- text: match[0],
|
|
|
- index: match.index,
|
|
|
- length: match[0].length
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // 从后向前替换,避免索引变化
|
|
|
- for (let i = matches.length - 1; i >= 0; i--) {
|
|
|
- const matchInfo = matches[i];
|
|
|
- const phoneText = matchInfo.text;
|
|
|
- const cleanNumber = phoneText.replace(/-/g, '');
|
|
|
-
|
|
|
- // 保存电话号码信息
|
|
|
- phoneNumbers.unshift({
|
|
|
- phoneText: phoneText,
|
|
|
- cleanNumber: cleanNumber
|
|
|
- });
|
|
|
-
|
|
|
- // 替换为带颜色的HTML
|
|
|
- const before = processedContent.substring(0, matchInfo.index);
|
|
|
- const after = processedContent.substring(matchInfo.index + matchInfo.length);
|
|
|
- processedContent = before +
|
|
|
- `<span style="color:#007AFF;">${phoneText}</span>` +
|
|
|
- after;
|
|
|
- }
|
|
|
-
|
|
|
- this.setData({
|
|
|
- phoneNumbers: phoneNumbers
|
|
|
- });
|
|
|
-
|
|
|
- return processedContent;
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad(options) {
|
|
|
+
|
|
|
},
|
|
|
|
|
|
- // 处理电话号码点击事件
|
|
|
- handlePhoneTap: function(e) {
|
|
|
- // 获取点击的位置
|
|
|
- const touchX = e.detail.x;
|
|
|
- const touchY = e.detail.y;
|
|
|
-
|
|
|
- // 获取保存的电话号码
|
|
|
- const phoneNumbers = this.data.phoneNumbers;
|
|
|
- if (phoneNumbers && phoneNumbers.length > 0) {
|
|
|
- // 弹出操作菜单让用户选择
|
|
|
- wx.showActionSheet({
|
|
|
- itemList: phoneNumbers.map(item => `拨打: ${item.phoneText}`),
|
|
|
- success: (res) => {
|
|
|
- if (res.tapIndex >= 0) {
|
|
|
- const selectedPhone = phoneNumbers[res.tapIndex].cleanNumber;
|
|
|
- wx.makePhoneCall({
|
|
|
- phoneNumber: selectedPhone,
|
|
|
- fail: (err) => {
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady() {
|
|
|
+
|
|
|
},
|
|
|
|
|
|
- onLoad: function (options) {
|
|
|
- const app = getApp();
|
|
|
- // 从全局数据中获取用户须知信息
|
|
|
- const userNotices = app.globalData.currentAccountInfo?.userNotices || '';
|
|
|
-
|
|
|
- // 处理电话号码
|
|
|
- const processedContent = this.processPhoneNumbers(userNotices);
|
|
|
-
|
|
|
- this.setData({
|
|
|
- 'noticeDetail.content': processedContent
|
|
|
- });
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow() {
|
|
|
+
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * 返回上一页
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
- goBack: function() {
|
|
|
- wx.navigateBack();
|
|
|
+ onHide() {
|
|
|
+
|
|
|
},
|
|
|
-})
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage() {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|