账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    关于iView的Notification编译出错的问题。
    36
    0

    使用了iview-admin模版搭建后台系统。

    dev模式下一切正常。

    当执行npm run build的时候出现了下面的错误

    ERROR in main.e53c38756696d4c01357.js from UglifyJs
    Unexpected token: operator (>) [main.e53c38756696d4c01357.js:3795,84]
    

    然后去具体位置查看,代码如下:

    __WEBPACK_IMPORTED_MODULE_0__notification_vue___default.a.newInstance = properties => {
        const _props = properties || {};
    
        const Instance = new __WEBPACK_IMPORTED_MODULE_1_vue__["default"]({
            data: _props,
            render (h) {
                return h(__WEBPACK_IMPORTED_MODULE_0__notification_vue___default.a, {
                    props: _props
                });
            }
        });
    
        const component = Instance.$mount();
        document.body.appendChild(component.$el);
        const notification = Instance.$children[0];
    
        return {
            notice (noticeProps) {
                notification.add(noticeProps);
            },
            remove (name) {
                notification.close(name);
            },
            component: notification,
            destroy (element) {
                notification.closeAll();
                setTimeout(function() {
                    document.body.removeChild(document.getElementsByClassName(element)[0]);
                }, 500);
            }
        };
    };

    第一行就是报错的地方,应该是=>报错了,这是ES6语法,然后去查看了iview源码对应的地方:

    import Notification from './notification.vue';
    import Vue from 'vue';
    
    Notification.newInstance = properties => {
        const _props = properties || {};
    
        const Instance = new Vue({
            data: _props,
            render (h) {
                return h(Notification, {
                    props: _props
                });
            }
        });
    
        const component = Instance.$mount();
        document.body.appendChild(component.$el);
        const notification = Instance.$children[0];
    
        return {
            notice (noticeProps) {
                notification.add(noticeProps);
            },
            remove (name) {
                notification.close(name);
            },
            component: notification,
            destroy (element) {
                notification.closeAll();
                setTimeout(function() {
                    document.body.removeChild(document.getElementsByClassName(element)[0]);
                }, 500);
            }
        };
    };
    
    export default Notification;

    我查看了其他文件,包括这个报错的文件的其他部分,都是已经从ES6转换成了ES5的,就这一个地方没有转换,很奇怪,不知道是什么原因。

    附上.babelrc配置:

    {
        "presets": ["es2015", "stage-3"],
        "plugins": ["transform-runtime", "transform-vue-jsx"],
        "comments": true
    }

    webpack.base.config.js配置:

    {
        test: /iview\/.*?js$/,
        loader: 'babel-loader'
    },
    {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
    },
    {
        test: /\.js[x]?$/,
        include: [resolve('src')],
        exclude: /node_modules/,
        loader: 'happypack/loader?id=happybabel'
    }

    都是使用的iview-adminwebpack配置, 有遇到过这种情况的吗?

    求大神告知,感谢不尽,已经困扰好几天了。

    2
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 云上城桥 普通会员 1楼

      iView(Image View)是华为公司推出的一款原生的Android界面框架,它为开发者提供了丰富的控件和设计工具,可以用于创建各种高质量的视图、布局和交互界面。然而,如果在编译过程中遇到iView Notification的编译错误,以下是一些可能的原因和解决方法:

      1. 图片路径错误: iView Notification依赖于系统内置的Notification系统来显示通知,其中通常会包含一个包含图片的资源文件(例如,notification.png)作为通知的背景。如果在编译时找不到或路径错误,那么iView Notification可能无法正常显示。你可以检查以下步骤:
      2. 通过res目录找到notification.png资源文件。确保它在你的项目根目录或res/drawable目录下,而不是在某个特定的子目录下。
      3. 使用AndroidManifest.xml文件来指定Notification的资源路径。在application标签中添加以下属性:

      xml <application android:name=".YourApplicationName" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".NotificationActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> - 将res/drawable/notification.png资源文件替换为实际的图片文件路径。 - 在NotificationActivity中导入Notification类,确保它包含以下配置:

      ```java import androidx.annotation.Color; import androidx.annotation.NonNull; import androidx.annotation.StringRes;

      import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView;

      import androidx.appcompat.app.AppCompatActivity;

      import com.frostwire.xfiggen4android.builtin.iView.ImageView;

      public class NotificationActivity extends AppCompatActivity {

      private static final int NOTIFICATION_ID = 1;
      private ImageView imageView;
      private TextView textView;
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_notification);
      
          imageView = findViewById(R.id.notification_image);
          textView = findViewById(R.id.notification_text);
      
          // 在这里设置Notification的配置和图片资源
          Intent intent = new Intent(this, NotificationActivity.class);
          intent.putExtra(NOTIFICATION_ID, 1);
          intent.putExtra(NOTIFICATION_TEXT, "This is a notification with a picture!");
      
          // 设置Notification的背景和显示方式
          Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon);
          imageView.setImageBitmap(bitmap);
          textView.setText(R.string.notification_text);
      
          // 显示Notification
          if (savedInstanceState != null) {
              imageView.setImageResource(savedInstanceState.getInt(NOTIFICATION_ID));
          } else {
              // If the activity is launched from a splash screen or during boot, show the notification as soon as the activity starts.
              displayNotification();
          }
      }
      
      private void displayNotification() {
          Intent intent = new Intent(this, NotificationActivity.class);
          intent.putExtra(NOTIFICATION_ID, 1);
          intent.putExtra(NOTIFICATION_TEXT, "This is a new notification!");
      
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
          // If you want to customize the notification, you can use the following method to show a different notification badge or text:
          // Intent i = new Intent(this, AnotherActivity.class);
          // i.putExtra("new_notification", true);
          // i.putExtra("badge", 5);
          // i.putExtra("text", "New notification with badge 5!");
          // PendingIntent pendingIntent2 = PendingIntent.getActivity(this, 0, i, 0);
          // // This is how you can show the badge in the notification:
          // imageView.setContentUri(pendingIntent2.getPendingIntent().getBroadcastReceiver().onReceive(this, new IntentFilter()));
          // // This is how you can set the text in the notification:
          // imageView.setText(pendingIntent2.getPendingIntent().getBroadcastReceiver().onReceive(this, new IntentFilter()));
          }
      

      } `` 2. 图片资源路径错误: iView Notification需要一个包含图片的资源文件(例如,notification.png),这通常在res/drawable目录下。如果你在编译时未正确地指定这个资源路径,那么iView Notification可能无法正常显示。你可以检查以下步骤: - 在res目录下找到notification.png资源文件。 - 在AndroidManifest.xml文件中,确保notification.png资源文件在你的项目根目录或res/drawable目录下,而不是在某个特定的子目录下。 - 在application`标签中添加以下属性:

      xml <application android:name=".YourApplicationName" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".NotificationActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> - 将res/drawable/notification.png资源文件替换为实际的图片文件路径。 - 在NotificationActivity中导入Notification类,确保它包含以下配置:

      ```java import androidx.annotation.Color; import androidx.annotation.NonNull; import androidx.annotation.StringRes;

      import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView;

      import androidx.appcompat.app.AppCompatActivity;

      import com.frostwire.xfiggen4android.builtin.iView.ImageView;

      public class NotificationActivity extends AppCompatActivity {

      private static final int NOTIFICATION_ID = 1;
      private ImageView imageView;
      private TextView textView;
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_notification);
      
          imageView = findViewById(R.id.notification_image);
          textView = findViewById(R.id.notification_text);
      
          // 在这里设置Notification的配置和图片资源
          Intent intent = new Intent(this, NotificationActivity.class);
          intent.putExtra(NOTIFICATION_ID, 1);
          intent.putExtra(NOTIFICATION_TEXT, "This is a notification with a picture!");
      
          // 设置Notification的背景和显示方式
          Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon);
          imageView.setImageBitmap(bitmap);
          textView.setText(R.string.notification_text);
      
          // 显示Notification
          if (savedInstanceState != null) {
              imageView.setImageResource(savedInstanceState.getInt(NOTIFICATION_ID));
          } else {
              // If the activity is launched from a splash screen or during boot, show the notification as soon as the activity starts.
              displayNotification();
          }
      }
      
      private void displayNotification() {
          Intent intent = new Intent(this, NotificationActivity.class);
          intent.putExtra(NOTIFICATION_ID, 1);
          intent.putExtra(NOTIFICATION_TEXT, "This is a new notification!");
      
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
          // If you want to customize the notification, you can use the following method to show a different notification badge or text:
          // Intent i = new Intent(this, AnotherActivity.class);
          // i.putExtra("new_notification", true);
          // i.putExtra("badge", 5);
          // i.putExtra("text", "New notification with badge 5!");
          // PendingIntent pendingIntent2 = PendingIntent.getActivity(this, 0, i, 0);
          // // This is how you can show the badge in the notification:
          // imageView.setContentUri(pendingIntent2.getPendingIntent().getBroadcastReceiver().onReceive(this, new IntentFilter()));
          // // This is how you can set the text in the notification:
          // imageView.setText(pendingIntent2.getPendingIntent().getBroadcastReceiver().onReceive(this, new IntentFilter()));
          }
      

      } ``` 3. Android Support Library版本过低: iView Notification依赖于Android Support Library,如果你的Android版本低于最新版本(例如,Android 11),那么可能无法正确使用iView Notification。你可以在AndroidManifest.xml文件中添加以下依赖:

      xml <application android:name=".YourApplicationName" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="30" android:usesPreviewCompat="true" /> <activity android:name=".NotificationActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 4. AndroidManifest.xml文件配置错误: iView

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部