Browse Source

格式化手机号

loki 3 years ago
parent
commit
d91e3bb8bb
1 changed files with 12 additions and 1 deletions
  1. 12 1
      src/containers/accountSelect/AccountSelect.vue

+ 12 - 1
src/containers/accountSelect/AccountSelect.vue

@@ -17,7 +17,7 @@
     >
       <span style="float: left">{{ item.nickname }}</span>
       <span style="float: right; color: #8492a6; font-size: 13px">{{
-        item.mobileNumber
+        item.mobileNumber | phoneFormat
       }}</span>
     </el-option>
   </el-select>
@@ -29,6 +29,17 @@ import { getSelectList } from '@/api/system/account';
 export default {
   name: 'AccountSelect',
 
+  filters: {
+    phoneFormat: function(str) {
+      if (!str) {
+        return '-';
+      }
+      let pattern = /^(\d{3})(\d{4})(\d{4})$/;
+      console.log(str.replace(pattern, `$1-$2-$3`));
+      return str.replace(pattern, `$1-$2-$3`);
+    }
+  },
+
   props: {
     value: {
       type: String,